[video output=day647 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Debugging Simplified Lighting" vod_platform=youtube id=uWCt4b4ukAA annotator=Miblo] [0:00][Recap and set the stage for the day][:speech] [3:14][Demo the :lighting :performance][:run] [4:19][Describe the old eight-ray octahedral :lighting][:research] [7:06][Increase the SampleBatch loop from 16 to 64 in FullCast()][:lighting] [7:22][Our :performance has degraded][:lighting :run] [7:28][Decrease the SampleBatch loop from 64 to 8 in FullCast()][:lighting] [7:36][We could easily hit 60 FPS][:lighting :performance :run] [8:05][Consider moving the SampleBatch loop down to GridRayCast()][:lighting :research] [10:27][Consider analysing the :sampling distribution of FullCast()][:lighting :research] [12:17][Move the SampleBatch loop from FullCast() down to GridRayCast()][:lighting] [14:17][Check the call stack of GridRayCast() for EntropyIndex][:lighting :research] [15:16][Change FullCast() to take Entropy not as a pointer, and setup ComputeLightPropagationWork() increment the Entropy][:lighting :prng] [16:20][Reacquaint ourselves with our random number generation][:prng :research] [20:39][Make ComputeLightPropagationWork() get Entropy from RandomSeedOffset()][:lighting :prng] [21:57][Consider usage of our random number code, and then just casting all 16 octahedrons][:lighting :prng :research] [24:49][Remove entropy from FullCast() and make GridRayCast() just sample all the octahedrons][:lighting] [31:41][Reacquaint ourselves with the sample direction picking code in GridRayCast()][:lighting :research] [36:09][Fix GridRayCast() to correctly step through the :lighting table] [37:56][Consider structuring the :lighting table with Rows being prime, and Octahedrons being interior][:research] [39:12][Make GridRayCast() take an Sy value from FullCast(), for stepping through the sample table][:lighting] [41:36][Remove Entropy from the call to FullCast() in ComputeLightPropagationWork()][:lighting] [42:09][Our :lighting is now stable][:run] [42:27][Increase tUpdateBlend from 1/60 to 15/60 in UpdateLighting()][:lighting] [42:56][The :lighting doesn't seem to line up correctly when shifting around][:run] [44:16][\~28ms per frame, and \~82% frame time on ComputeLightPropagationWork][:lighting :performance :run] [45:45][Determine to debug the :lighting computation][:research] [46:54][Walk through GridRayCast() and ComputeWalkTable() to refresh our memories][:lighting :research] [52:52][Toggle on DebugDrawOctahedralValues() in UpdateLighting()][:"debug visualisation" :lighting] [53:01][Check out the light probes][:"debug visualisation" :lighting :run] [54:11][Toggle on DebugDrawSpatialGrid() in UpdateLighting()][:"debug visualisation" :lighting] [54:21][Flood the debug system with vertices][:run] [54:49][Make UpdateLighting() double the MaxDebugLineCount][:"debug visualisation" :lighting] [54:56][Still flood the debug system with vertices][:run] [55:03][Make PushLightingRenderValues() batch up the debug lines into 16-bit capable chunks][:"debug visualisation" :lighting] [58:42][Still flood the debug system with vertices][:"debug visualisation" :lighting :run] [58:58][Investigate the bug in our :lighting debug line batching][:"debug visualisation"] [1:00:24][Decrease the batch size from U16Max to 4096 in PushLightingRenderValues()][:"debug visualisation" :lighting] [1:00:45][Check out our spatial grid][:"debug visualisation" :lighting :run] [1:03:05][Consider restoring our :lighting alignment][:run] [1:04:57][Make UpdateLighting() offset the AtlasMinCorner by half a voxel][:lighting] [1:07:34][Admire our light poisoning][:lighting :run] [1:09:30][Comment out the AtlasMinCorner offset in UpdateLighting()][:lighting] [1:09:43][Traverse the orphanage, pondering the offset-induced :lighting poisoning][:run] [1:10:23][Consider why the :lighting alignment affects its feedback behaviour][:research] [1:11:28][Let UpdateLighting() offset the AtlasMinCorner by half a voxel][:lighting] [1:11:31][Take one last look at the light poisoning][:lighting :run] [1:11:58][Toggle off DebugDrawOctahedralValues() and DebugDrawSpatialGrid() in UpdateLighting()][:"debug visualisation" :lighting] [1:12:14][Consider it to be a sampling direction bug][:lighting :run] [1:13:16][Toggle on DebugDrawOctahedralValues() in UpdateLighting(), and the octahedral map drawing][:"debug visualisation" :lighting] [1:13:40][Check out our octahedral map koosh balls][:"debug visualisation" :lighting :run] [1:15:06][Toggle on and make DebugDrawSpatialGrid() draw just the cell boundaries][:"debug visualisation" :lighting] [1:15:35][Check out the cell boundaries in relation to the octahedral map koosh balls][:"debug visualisation" :lighting :run] [1:16:10][Toggle on the occluder drawing in DebugDrawSpatialGrid()][:"debug visualisation" :lighting] [1:16:22][Light probes inside light sources inconsistently see light and no light][:"debug visualisation" :lighting :run] [1:18:27][@lfcdi][The hero's light box is sometimes red and sometimes green][:lighting] [1:18:33][Demo the spatial grid checkerboard colouring][:"debug visualisation" :lighting :run] [1:18:54][Toggle off the non-occluder drawing in DebugDrawSpatialGrid()][:"debug visualisation" :lighting] [1:19:04][Demo the spatial grid checkerboard colouring][:"debug visualisation" :lighting :run] [1:21:11][Determine to investigate the ray caster][:lighting :run] [1:21:30][@horrowind][In handmade_lighting.cpp: line 152 SampleDir = ... Should the first factor be Sy*16*8?][:lighting] [1:22:14][Explain the SampleDirectionTable indexing line in GridRayCast()][:lighting :research] [1:24:13][@horrowind][I was just wondering because the outer index did not seem to incorporate two factors][:lighting] [1:27:48][Set up to investigate the ray caster for bugs][:lighting :research] [1:29:42][Scour FullCast() for bugs][:lighting :research] [1:31:00][Make FullCast() write magenta into each SpecTexel inside geometry][:"debug visualisation" :lighting] [1:33:35][Admire our magenta light probes][:"debug visualisation" :lighting :run] [1:34:30][Lights incorrectly fail to pick up light][:"debug visualisation" :lighting :run] [1:35:27][@ciansweeney][Debugging :lighting is the biggest pain in the ass] [1:35:34][Optionally make FullCast() write black into each SpecTexel inside geometry][:"debug visualisation" :lighting] [1:36:12][Our "inside" light probes are now black][:"debug visualisation" :lighting :run] [1:36:28][Toggle off DebugDrawSpatialGrid() in UpdateLighting()][:"debug visualisation" :lighting] [1:37:01][Our light probes are picking up illogical light][:"debug visualisation" :lighting :run] [1:38:26][Consult the SampleDirectionTable for clues regarding our illogical light probes][:lighting :research] [1:40:23][@gregg_ink][So we got issues but that's not a problem for us because the worse they are, the faster we will fix them. Love that logic] [1:43:45][Check the Remainder code in FullCast()][:lighting :research] [1:47:00][The light probes inside geometry are correct, but our shifting block-copy is wrong][:lighting :run] [1:48:11][Check that GridRayCast() and ComputeWalkTable() work in consort][:lighting :research] [1:50:15][Consider replacing the walk table with on-the-fly computation][:lighting :research] [1:52:21][Check that GridRayCast() and ComputeWalkTable() work in consort (cont.)][:lighting :research] [1:57:14][Determine to draw a particular ray cast][:"debug visualisation" :lighting :run] [1:58:37][Reduce the LightSamplingWalkTable pointer array from 8 to 4 in lighting_solution][:"data structure" :lighting] [1:59:15][The :lighting looks the same][:run] [1:59:32][Scour GridRayCast() for bugs][:lighting :research] [2:03:00][Increase MaxCostPerRay from 8 to 16 in UpdateLighting()][:lighting] [2:03:52][\~38ms per frame, and \~69% frame time on ComputeLightPropagationWork][:lighting :performance :run] [2:04:21][Toggle off DebugDrawOctahedralValues() in UpdateLighting()][:"debug visualisation" :lighting] [2:04:27][\~27ms per frame, and \~81% frame time on ComputeLightPropagationWork][:lighting :performance :run] [2:04:51][Toggle on DebugDrawOctahedralValues() and decrease MaxCostPerRay back from 16 to 8 in UpdateLighting()][:lighting] [2:06:41][Re-enable ray drawing in GridRayCast()][:"debug visualisation" :lighting] [2:09:04][Reacquaint ourselves with RectCenterDim() and the ProbeSamplePSingle value in GridRayCast()][:lighting :research] [2:12:17][Enable GridRayCast() to use ProbeSamplePSingle and ProbeSampleNSingle for drawing][:"debug visualisation" :lighting] [2:14:05][Consider supporting picking of a particular ray][:lighting :research] [2:15:51][Re-enable ray cast drawing in FullCast()][:"debug visualisation" :lighting] [2:19:12][Hunt in vain for our drawn ray cast][:"debug visualisation" :lighting :run] [2:19:36][Toggle off DebugDrawOctahedralValues() in UpdateLighting()][:"debug visualisation" :lighting] [2:19:57][Hunt in vain for our drawn ray cast][:"debug visualisation" :lighting :run] [2:20:12][Decrease DebugGridIndex from 717 to 200 and DebugRayIndex from 531 to 0 in UpdateLighting()][:"debug visualisation" :lighting] [2:21:27][Hunt in vain for our drawn ray cast][:"debug visualisation" :lighting :run] [2:21:42][Elevate GRID_RAY_CAST_DEBUGGING to the top of handmade_lighting.h][:lighting] [2:22:46][Break in to FullCast() to find that we never get to our DebugGridIndex of 200][:lighting :run] [2:24:41][The spatial partition is half the voxel dimensions, a mere 96][:lighting :research] [2:25:43][Decrease DebugGridIndex from 200 to 30 in UpdateLighting()][:"debug visualisation" :lighting] [2:26:04][Break in to FullCast() and see our drawn ray cast][:"debug visualisation" :lighting :run] [2:28:03][Re-enable support for debug ray picking in FullCast(), introducing debug_ray_pick][:"data structure" :lighting] [2:34:05][Quick break for water and snacks][:admin] [2:34:34][@insobot][Allocates 256 megs, keeps playing. Employees are encouraged to kill yourself] [2:34:52][@bluemelon555][Are you providing the snacks?] [2:35:03][:afk] [2:47:31][Return with water and snacks][:admin] [2:48:41][@choosetheforce][I used to inhale that stuff as a kid] [2:48:51][Resume re-enabling support for debug ray picking in FullCast()][:lighting] [2:53:28][The magenta "expected direction" line does not go in the direction we ray cast][:"debug visualisation" :lighting :run] [2:55:12][Investigate the "expected" and "ray" direction misalignment in FullCast()][:lighting :research] [2:56:27][Try making FullCast() add 1 to the ExpectedDirection axes to account for the apron][:lighting] [2:56:47][The "expected" and "ray" directions remain misaligned][:"debug visualisation" :lighting :run] [2:56:59][Investigate the "expected" and "ray" direction misalignment in FullCast() and GridRayCast()][:lighting :research] [2:58:29][The "expected" and "ray" lines only need to come out of the same face of the octahedron][:"debug visualisation" :lighting :run] [2:58:56][Re-enable editing of the ray picking values in DEBUGInteract() and DEBUGBeginInteract()][:lighting :ui] [3:03:05][Try editing GridIndex in-game][:"debug visualisation" :lighting :run :ui] [3:04:06][Clamp the DebugTick values in FullCast()][:lighting] [3:06:53][GridIndex 48 yields two sets of ray casting][:"debug visualisation" :lighting :run :ui] [3:07:48][Replace GridIndex with a v3s AtlasIndex in debug_ray_pick, for more specific ray picking][:"data structure" :lighting] [3:11:09][Introduce a v3s version of Clamp()][:mathematics] [3:12:11][Make FullCast() keep the AtlasIndex in range][:lighting] [3:12:25][Try unsuccessfully to edit AtlasIndex][:"debug visualisation" :lighting :run :ui] [3:13:10][Add s32 editing support to DEBUGInteract() and DEBUGBeginInteract()][:lighting :ui] [3:13:48][Try editing our AtlasIndex values][:"debug visualisation" :lighting :run :ui] [3:14:52][Add DevUI_Interaction_TickValue to edit integer values by clicking (rather than dragging)][:lighting :ui] [3:17:48][Decrementing by clicking works, but incrementing does not][:"debug visualisation" :lighting :run :ui] [3:18:07][Fix DEBUGInteract() to increment integer values by clicking][:lighting :ui] [3:18:21][Click-and-hold increments integer values][:"debug visualisation" :lighting :run :ui] [3:18:34][Make DEBUGEndInteract() rather than DEBUGInteract() handle integer editing by clicking][:lighting :ui] [3:19:21][Our integer editing is more sane, but still doesn't clamp][:"debug visualisation" :lighting :run :ui] [3:20:47][Atlas (10, 4, 1) on our octahedral map has a straight-down expected direction][:"debug visualisation" :lighting :run :ui] [3:21:39][Investigate our straight-down expected direction][:lighting :research] [3:23:50][@gregg_ink][Are light bleed and light poisoning the same thing?][:lighting] [3:26:34][Inspect atlas (10, 4, 1)][:"debug visualisation" :lighting :run] [3:27:04][Initialise AtlasIndex to 10, 4, 1 UpdateLighting()][:lighting] [3:27:14][Ray casting on AtlasIndex (10, 4, 1) fails from Octahedron 4 onwards][:"debug visualisation" :lighting :run] [3:27:42][Investigate SampleDirectionTable and GridRayCast() for the source of our ray casting failure][:lighting :research] [3:31:20][Octahedron 4 to 15 remain incorrect][:"debug visualisation" :lighting :run] [3:32:22][Check again that GridRayCast() and ComputeWalkTable() work in consort][:lighting :research] [3:35:05][Initialise DirOffset in GridRayCast() for easy inspection][:lighting] [3:35:52][Step in to GridRayCast() and inspect DirOffset and RayDSingle, to find values we didn't think existed in handmade_sampling_spheres.inl][:lighting :run] [3:40:23][@ono_sendai_][Is this 2D or 3D global illumination?][:lighting] [3:41:55][Determine to fix GenerateOctahedralLightingPattern() next time][:lighting :research] [3:46:16][@poissonprocess][Poisson distributions!][:sampling] [3:46:25][Consider keeping Poisson distribution :sampling][:lighting :research] [3:48:20][@spacenaming][Will it still be mapped to the octahedral map? Because if so, couldn't we just generate the noise on there? That is a square surface, right?][:lighting] [3:49:44][Determine to rebuild SampleDirectionTable next time][:lighting :research] [3:50:19][Set up GridRayCast() to traverse the SampleDirectionTable in a single loop][:lighting] [3:52:37][Call it here, with the determination to rebuild SampleDirectionTable next time][:speech] [3:53:21][Consider the possibility of smarter ways to batch up ray processing][:lighting :research] [3:54:32][Thank you, everyone][:speech] [/video]