Skip to content

Commit dc940eb

Browse files
committed
Support for multi-bounce GI, add "Write to Disk" button, fix bug when using a 128³ voxel grid, Add example instancing effect
1 parent 11e9ad6 commit dc940eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+360
-248
lines changed

Diff for: Code/GUI/BufferViewerGUI.py

+8
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ def showDetail(self, tex, coord):
193193

194194
backBtn = BetterButton(
195195
self.buffersParent, 230, 2, "Back", callback=self.renderBuffers)
196+
writeBtn = BetterButton(
197+
self.buffersParent, 350, 2, "Write to Disk", callback=partial(self.writeTexToDisk, tex))
198+
199+
def writeTexToDisk(self, tex):
200+
print "Writing",tex,"to disk .."
201+
Globals.base.graphicsEngine.extractTextureData(tex, Globals.base.win.getGsg())
202+
tex.write(tex.getName() + ".png")
203+
print "Done!"
196204

197205
def onMouseOver(self, node, a):
198206
node['frameColor'] = (1, 1, 1, 0.4)

Diff for: Code/GUI/FastText.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _prepareFontTextures(self):
7979
self.fontTex.setMinfilter(Texture.FTLinear)
8080
self.fontTex.setMagfilter(Texture.FTLinear)
8181
self.fontTex.setAnisotropicDegree(16)
82+
self.fontTex.setFormat(Texture.FRgba)
8283

8384
def _loadCharset(self):
8485
self.charset = """ !"#$%&'()*+,-./"""
@@ -109,13 +110,11 @@ def _makeFontShader(self):
109110
texcoord = clamp(p3d_MultiTexCoord0, halfOffset, 1.0 - halfOffset) / vec2(16,6) + offsetCoordReal;
110111
vec4 offset = vec4(gl_InstanceID*size.x*0.56 , 0, 0, 0) +
111112
vec4(pos.x, 0, pos.y, 0);
112-
113113
vec4 finalPos = p3d_Vertex * vec4(size.xxx, 1.0) + offset;
114114
gl_Position = p3d_ModelViewProjectionMatrix * finalPos;
115115
}
116116
""", """
117117
#version 150
118-
#pragma file FastText.fragment
119118
in vec2 texcoord;
120119
uniform sampler2D font;
121120
uniform vec3 color;
@@ -149,9 +148,9 @@ def _makeSquare(self):
149148
c.setFrame(-0.5, 0.5, -0.5, 0.5)
150149
self.square = NodePath(c.generate())
151150
self.square.setShaderInput("font", self.fontTex)
152-
self.square.setShader(self.fontShader, 100)
151+
self.square.setShader(self.fontShader, 1000)
153152
self.square.setAttrib(
154-
TransparencyAttrib.make(TransparencyAttrib.MAlpha), 100)
153+
TransparencyAttrib.make(TransparencyAttrib.MAlpha), 1000)
155154
self.square.reparentTo(Globals.base.aspect2d)
156155
return self.square
157156

Diff for: Code/GlobalIllumination.py

+21-27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from SettingsManager import SettingsManager
1717
from MemoryMonitor import MemoryMonitor
1818
from DistributedTaskManager import DistributedTaskManager
19+
from GUI.FastText import FastText
1920

2021
from RenderPasses.GlobalIlluminationPass import GlobalIlluminationPass
2122
from RenderPasses.VoxelizePass import VoxelizePass
@@ -62,12 +63,12 @@ def __init__(self, pipeline):
6263
self.voxelGridSize = self.pipeline.settings.giVoxelGridSize
6364

6465
# Grid resolution in pixels
65-
self.voxelGridResolution = 64
66+
self.voxelGridResolution = 128
6667

6768
# Has to be a multiple of 2
68-
self.distributionSteps = 30
69-
70-
self.slideCount = int(math.sqrt(self.voxelGridResolution))
69+
self.distributionSteps = 40
70+
self.slideCount = int(self.voxelGridResolution / 8)
71+
self.slideVertCount = self.voxelGridResolution / self.slideCount
7172

7273
self.bounds = BoundingBox()
7374
self.renderCount = 0
@@ -85,24 +86,16 @@ def __init__(self, pipeline):
8586
self.frameIndex = 0
8687
self.steps = []
8788

88-
89-
9089
def _createDebugTexts(self):
9190
""" Creates a debug overlay to show GI status """
9291
self.debugText = None
9392
self.buildingText = None
9493

9594
if self.pipeline.settings.displayDebugStats:
96-
try:
97-
from .GUI.FastText import FastText
98-
self.debugText = FastText(pos=Vec2(
99-
Globals.base.getAspectRatio() - 0.1, 0.88), rightAligned=True, color=Vec3(1, 1, 0), size=0.03)
100-
self.buildingText = FastText(pos=Vec2(-0.3, 0), rightAligned=False, color=Vec3(1, 1, 0), size=0.03)
101-
self.buildingText.setText("PREPARING GI, PLEASE BE PATIENT ....")
102-
103-
except Exception, msg:
104-
self.debug(
105-
"GI-Debug text is disabled because FastText wasn't loaded")
95+
self.debugText = FastText(pos=Vec2(
96+
Globals.base.getAspectRatio() - 0.1, 0.88), rightAligned=True, color=Vec3(1, 1, 0), size=0.03)
97+
self.buildingText = FastText(pos=Vec2(-0.3, 0), rightAligned=False, color=Vec3(1, 1, 0), size=0.03)
98+
self.buildingText.setText("PREPARING GI, PLEASE BE PATIENT ....")
10699

107100
def stepVoxelize(self, idx):
108101

@@ -126,14 +119,13 @@ def stepVoxelize(self, idx):
126119
self.buildingText.remove()
127120
self.buildingText = None
128121

129-
self.voxelizePass.voxelizeSceneFromDirection(self.gridPosTemp[0], "yxz"[idx])
122+
self.voxelizePass.voxelizeSceneFromDirection(self.gridPosTemp[0], "xyz"[idx])
130123

131124

132125
def stepDistribute(self, idx):
133126

134127
if idx == 0:
135-
self.convertGridTarget.setActive(True)
136-
128+
self.convertGridTarget.setActive(True)
137129

138130
self.distributeTarget.setActive(True)
139131

@@ -143,14 +135,14 @@ def stepDistribute(self, idx):
143135

144136
if idx == self.distributionSteps - 1:
145137
self.publishGrid()
146-
147-
148138
dests = self.dataTextures
149139

150140
for i in xrange(5):
151141
self.distributeTarget.setShaderInput("src" + str(i), sources[i])
152142
self.distributeTarget.setShaderInput("dst" + str(i), dests[i])
153143

144+
self.distributeTarget.setShaderInput("isLastStep", idx >= self.distributionSteps-4)
145+
154146
def publishGrid(self):
155147
""" This function gets called when the grid is ready to be used, and updates
156148
the live grid data """
@@ -219,7 +211,7 @@ def setup(self):
219211
self.bindTo(Globals.render, "giData")
220212

221213
self.convertGridTarget = RenderTarget("ConvertGIGrid")
222-
self.convertGridTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideCount)
214+
self.convertGridTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideVertCount)
223215

224216
if self.pipeline.settings.useDebugAttachments:
225217
self.convertGridTarget.addColorTexture()
@@ -231,7 +223,7 @@ def setup(self):
231223
self.convertGridTarget.getColorTexture().setMagfilter(Texture.FTNearest)
232224

233225
self.clearGridTarget = RenderTarget("ClearGIGrid")
234-
self.clearGridTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideCount)
226+
self.clearGridTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideVertCount)
235227
if self.pipeline.settings.useDebugAttachments:
236228
self.clearGridTarget.addColorTexture()
237229
self.clearGridTarget.prepareOffscreenBuffer()
@@ -240,6 +232,7 @@ def setup(self):
240232
self.convertGridTarget.setShaderInput("voxelGenSrc" + color.upper(), self.generationTextures[idx])
241233
self.clearGridTarget.setShaderInput("voxelGenTex" + color.upper(), self.generationTextures[idx])
242234

235+
243236
# Create the data textures
244237
self.dataTextures = []
245238

@@ -267,10 +260,10 @@ def setup(self):
267260
self.pongDataTextures.append(texPong)
268261

269262
self.convertGridTarget.setShaderInput("voxelDataDest"+str(i), self.pingDataTextures[i])
270-
263+
# self.clearGridTarget.setShaderInput("voxelDataDest" + str(i), self.pongDataTextures[i])
271264

272265
# Set texture wrap modes
273-
for tex in self.pingDataTextures + self.pongDataTextures + self.dataTextures:
266+
for tex in self.pingDataTextures + self.pongDataTextures + self.dataTextures + self.generationTextures:
274267
tex.setMinfilter(Texture.FTNearest)
275268
tex.setMagfilter(Texture.FTNearest)
276269
tex.setWrapU(Texture.WMBorderColor)
@@ -283,7 +276,7 @@ def setup(self):
283276
tex.setMagfilter(Texture.FTLinear)
284277

285278
self.distributeTarget = RenderTarget("DistributeVoxels")
286-
self.distributeTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideCount)
279+
self.distributeTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideVertCount)
287280

288281
if self.pipeline.settings.useDebugAttachments:
289282
self.distributeTarget.addColorTexture()
@@ -294,6 +287,7 @@ def setup(self):
294287
self.distributeTarget.getColorTexture().setMinfilter(Texture.FTNearest)
295288
self.distributeTarget.getColorTexture().setMagfilter(Texture.FTNearest)
296289

290+
297291
# Create the various render targets to generate the mipmaps of the stable voxel grid
298292
# self.mipmapTargets = []
299293
# computeSize = self.voxelGridResolution
@@ -326,7 +320,7 @@ def setup(self):
326320
if False:
327321
self.voxelCube = loader.loadModel("Box")
328322
self.voxelCube.reparentTo(render)
329-
self.voxelCube.setTwoSided(True)
323+
# self.voxelCube.setTwoSided(True)
330324
self.voxelCube.node().setFinal(True)
331325
self.voxelCube.node().setBounds(OmniBoundingVolume())
332326
self.voxelCube.setInstanceCount(self.voxelGridResolution**3)

Diff for: Code/LightManager.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from RenderPasses.ShadowedLightsPass import ShadowedLightsPass
3232
from RenderPasses.ExposurePass import ExposurePass
3333

34+
from GUI.FastText import FastText
35+
3436
pstats_ProcessLights = PStatCollector("App:LightManager:ProcessLights")
3537
pstats_CullLights = PStatCollector("App:LightManager:CullLights")
3638
pstats_PerLightUpdates = PStatCollector("App:LightManager:PerLightUpdates")
@@ -298,16 +300,10 @@ def _createDebugTexts(self):
298300
self.lightsUpdatedDebugText = None
299301

300302
if self.pipeline.settings.displayDebugStats:
301-
try:
302-
from .GUI.FastText import FastText
303-
self.lightsVisibleDebugText = FastText(pos=Vec2(
304-
Globals.base.getAspectRatio() - 0.1, 0.84), rightAligned=True, color=Vec3(1, 1, 0), size=0.03)
305-
self.lightsUpdatedDebugText = FastText(pos=Vec2(
306-
Globals.base.getAspectRatio() - 0.1, 0.8), rightAligned=True, color=Vec3(1, 1, 0), size=0.03)
307-
308-
except Exception, msg:
309-
self.debug(
310-
"Overlay is disabled because FastText wasn't loaded")
303+
self.lightsVisibleDebugText = FastText(pos=Vec2(
304+
Globals.base.getAspectRatio() - 0.1, 0.84), rightAligned=True, color=Vec3(1, 1, 0), size=0.03)
305+
self.lightsUpdatedDebugText = FastText(pos=Vec2(
306+
Globals.base.getAspectRatio() - 0.1, 0.8), rightAligned=True, color=Vec3(1, 1, 0), size=0.03)
311307

312308
def _queueShadowUpdate(self, sourceIndex):
313309
""" Internal method to add a shadowSource to the list of queued updates. Returns

Diff for: Code/MemoryMonitor.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def _calculateTexSize(self, tex):
2121

2222
# Assign the texture format a size
2323
textureTypes = {
24-
6: 1, # ALPHA
24+
3: 1, # FRED
25+
6: 1, # ALPHA
2526
7: 3 * 1, # RGB (Unkown type, we will just assume 8 bit)
2627
9: 3 * 1, # FRGBA8
27-
12: 4 * 1, # RGBA (Unkown type, we will just assume 8 bit)
28-
18: 1, # LUMINANCE
29-
19: 2, # LUMINANCE_ALPHA
28+
12: 4 * 1,# RGBA (Unkown type, we will just assume 8 bit)
29+
18: 1, # LUMINANCE
30+
19: 2, # LUMINANCE_ALPHA
3031
16: 4 * 1, # RGBA8
3132
21: 4 * 2, # RGBA16
3233
22: 4 * 4, # RGBA32
@@ -40,6 +41,7 @@ def _calculateTexSize(self, tex):
4041
35: 4, # FR32
4142
}
4243

44+
4345
# Get format and compute size per component
4446
form = tex.getFormat()
4547
componentSize = 0
@@ -52,6 +54,13 @@ def _calculateTexSize(self, tex):
5254
# Fetch the amount of pixels
5355
pixelCount = tex.getXSize() * tex.getYSize() * tex.getZSize()
5456

57+
# Check for deprecated formats
58+
deprecated = [18, 19, 6]
59+
60+
if form in deprecated:
61+
# print "DEPRECATED FORMAT:", form, "USED BY",tex.getName()
62+
pass
63+
5564
# Mipmaps take approx 33% of the texture size, so just multiply the pixel
5665
# count by that amount
5766
if tex.usesMipmaps():

Diff for: Code/RenderPasses/AmbientOcclusionPass.py

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ def getRequiredInputs(self):
2323
"frameIndex": "Variables.frameIndex",
2424
"mainRender": "Variables.mainRender",
2525
"mainCam": "Variables.mainCam",
26-
"noiseTexture": "Variables.noise4x4",
27-
"viewSpaceNormals": "ViewSpacePass.normals",
28-
"viewSpacePosition": "ViewSpacePass.position",
2926
"depthTex": "DeferredScenePass.depth",
3027
"cameraPosition": "Variables.cameraPosition",
3128
"currentViewMat": "Variables.currentViewMat",

Diff for: Code/RenderPasses/ViewSpacePass.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def getRequiredInputs(self):
2222
"depthTex": "DeferredScenePass.depth",
2323
"mainRender": "Variables.mainRender",
2424
"mainCam": "Variables.mainCam",
25-
"currentViewMat": "Variables.currentViewMat"
25+
"currentViewMat": "Variables.currentViewMat",
26+
"currentProjMatInv": "Variables.currentProjMatInv",
2627
}
2728

2829
def create(self):

Diff for: Code/RenderingPipeline.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def getDefaultSkybox(self, scale=60000):
225225
skytex.setWrapV(SamplerState.WMRepeat)
226226
skytex.setMinfilter(SamplerState.FTLinear)
227227
skytex.setMagfilter(SamplerState.FTLinear)
228+
skytex.setFormat(Texture.FRed)
228229
skybox.setShaderInput("skytex", skytex)
229230
self.setEffect(skybox, "Effects/Skybox/Skybox.effect", {
230231
"castShadows": False,
@@ -554,8 +555,8 @@ def _setGuiShaders(self):
554555
shader = Shader.load(Shader.SLGLSL, "Shader/GUI/vertex.glsl", "Shader/GUI/fragment.glsl")
555556
for target in [self.showbase.aspect2d, self.showbase.render2d, self.showbase.pixel2d,
556557
self.showbase.aspect2dp, self.showbase.render2dp, self.showbase.pixel2dp]:
557-
target.setShader(shader, 50)
558-
558+
# target.setShader(shader, 50)
559+
pass
559560

560561
def create(self):
561562
""" Creates the pipeline """

Diff for: Config/configuration.prc

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ gl-force-fbo-color false
120120

121121

122122
# Set the minimum openGL version
123-
gl-version 3 2
123+
#gl-version 3 2
124124

125125
# Animations on the gpu. This is WIP, the default shader has to get adjusted first!
126126
# hardware-animated-vertices #t
@@ -172,6 +172,8 @@ gl-debug-object-labels #f
172172

173173

174174

175+
175176
# Default window settings
176177
depth-bits 0
177-
color-bits 0
178+
color-bits 0
179+

Diff for: Config/pipeline.ini

+5-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
# Size of the generated cubemap for the scattering, used for the ambient term
8888
# and reflections
89-
scatteringCubemapSize = 256
89+
scatteringCubemapSize = 128
9090

9191

9292
[SSLR]
@@ -111,8 +111,9 @@
111111
# Todo: Write explanation of all techniques
112112
occlusionTechnique = "HBAO"
113113

114-
# Radius of the occlusion
115-
occlusionRadius = 1.0
114+
# Radius of the occlusion in pixels, higher pixels mean better results but also
115+
# worse performance.
116+
occlusionRadius = 10.0
116117

117118
# Strength of the occlusion. 1.0 is default
118119
occlusionStrength = 1.0
@@ -266,4 +267,4 @@
266267

267268
# Wheter to a attach a color texture to buffers which don't really produce
268269
# a useful color texture. This is mainly helpful for debugging
269-
useDebugAttachments = True
270+
useDebugAttachments = False

Diff for: Data/Textures/font.png

3.83 KB
Loading

0 commit comments

Comments
 (0)