[video output=day438 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Switching to Cosine-weighted Poisson Sampling" vod_platform=youtube id=1SjF9NEcTU8 annotator=Miblo]
[0:01][Recap and set the stage for the day with a few words on the recent news around ray tracing][:speech]
[2:58][:Run the game to see our current :lighting][:rendering]
[4:38][Toggle ComputeLightPropagation() to sample the :lighting using the old white noise scheme][:prng :rendering :statistics]
[5:10][Show the :lighting using this method][:rendering :run]
[5:40][Switch ComputeLightPropagation() back to our customised polar sampling][:lighting :rendering :statistics]
[5:44][See how the :lighting changes][:rendering :run]
[6:40][Enable ComputeLightPropagation() to display our :lighting :"debug visualisation"][:rendering]
[9:09][:Run the game to see our :lighting :"debug visualisation"][:rendering :statistics]
[9:42][Toggle back to the customised polar sampling in ComputeLightPropagation()][:lighting :rendering :statistics]
[9:47][:Run the game to see that this sampling is slightly wrong][:"debug visualisation" :lighting :rendering :statistics]
[11:44][Multiply SamplePointEntropy in to SampleD4x in ComputeLightPropagation()][:lighting :prng :rendering :statistics]
[12:47][:Run the game to see our varying :lighting sampling][:"debug visualisation" :rendering :statistics]
[13:33][Introduce a LIGHTING_PATTERN_GENERATOR() macro to generalise our generators and enable cycling through them][:lighting :rendering :statistics]
[17:35][Introduce GenerateLightingPattern() for InitLighting() to call][:lighting :rendering :statistics]
[26:57][Introduce a GenerateWhiteNoiseSamples version of LIGHTING_PATTERN_GENERATOR()][:lighting :rendering :statistics]
[29:52][Read through how the :"debug system" could handle strings][:research]
[34:35][Add a DebugType_string_ptr debug_type][:"debug system"]
[36:09][Introduce DEBUG_STRING() for inclusion in GenerateLightingPattern()][:"debug system" :lighting :rendering :statistics]
[39:19][:Run the game to see that our new DEBUG_STRING() is a little off][:"debug system"]
[39:47][Switch to -Od and determine to implement ceilf() and floorf() functions[ref
    site=Intel
    page="Intel Intrinsics Guide"
    url=https://software.intel.com/sites/landingpage/IntrinsicsGuide/]]
[47:50][Introduce FloorReal32ToInt32() and CeilReal32ToInt32() using SSE4.1 instructions[ref
    site=Intel
    page="Intel Intrinsics Guide"
    url=https://software.intel.com/sites/landingpage/IntrinsicsGuide/]][:mathematics]
[50:17][Successfully compile and :run]
[51:15][Step in to LightingTest(), open the profiler and inspect our Event to see that our debug string didn't get processed as we want][:"debug system"]
[55:42][Add a DEBUG_B32() in GenerateLightingPattern()][:"debug system"]
[56:00][Open up the profiler to see that the entire :"debug system" isn't quite working in GenerateLightingPattern()]
[56:57][Move our test DEBUG_B32() from GenerateLightingPattern() to the repeatedly-called ComputeLightPropagation()][:"debug system"]
[57:21][:Run the game to see that it is correct, and consider why][:"debug system"]
[58:43][Store PatternName in lighting_solution][:"debug system"]
[59:24][:Run the game to see our GenerateWhiteNoiseSamples in the profiler][:"debug system"]
[59:34][Bind F9 to cycle through the :lighting pattern][:"input handling" :rendering]
[1:00:38][:Run the game and try cycling through the :lighting patterns, to see that the flicker is way lower with the Poisson sampling scheme][:rendering :statistics]
[1:02:00][Prevent LightingTest() from hard-enabling the debug lines][:"debug visualisation" :lighting :rendering]
[1:02:34][:Run the game and try cycling through the :lighting sampling schemes without the :"debug visualisation" lines][:rendering :statistics]
[1:04:22][Re-enable the snake to add more light into the scene][:"entity system"]
[1:05:32][See the scene with more lights, without harming our :performance][:lighting :rendering :run]
[1:06:57][Make GenerateLightingPattern() use Poisson sampling by default][:lighting :rendering :statistics]
[1:07:19][Consider our :lighting][:rendering :run :statistics]
[1:08:23][Excise superfluous code from RayCast() and increase rCloseEnough from 5 to 10 to gather light emission from further away][:lighting :rendering]
[1:08:56][:Run the game to see fewer :lighting errors][:rendering]
[1:10:08][Cosine-weighting][:blackboard :statistics]
[1:11:30][Prevent ComputeLightPropagation() from considering the angular falloff when computing the SampleColor][:lighting :rendering]
[1:11:57][:Run the game to see our brighter light, and determine to bias the sample generation upwards][:lighting :rendering :statistics]
[1:12:48][Projecting Poisson sampling upwards from a disc][:blackboard :lighting :rendering :statistics]
[1:13:54][Re-enable LightingTest() to draw our sampling pattern][:"debug visualisation" :lighting :rendering :statistics]
[1:16:07][Check out our Poisson pattern][:"debug visualisation" :lighting :rendering :run :statistics]
[1:16:30][Make our GeneratePoissonSamples generator produce samples on a disc][:lighting :rendering :statistics]
[1:21:09][Admire our nice distribution of points][:"debug visualisation" :lighting :rendering :run :statistics]
[1:21:21][Begin to make our GeneratePoissonSamples generator project our samples up][:lighting :rendering :statistics]
[1:22:54][Projecting samples upwards][:blackboard :statistics]
[1:24:46][Finish making our GeneratePoissonSamples generator project our samples up][:lighting :rendering :statistics]
[1:25:11][Check out our upwards-projected Poisson samples, and determine to check whether it is really cosine-weighted][:"debug visualisation" :lighting :rendering :run :statistics]
[1:28:03][View our ray cast :"debug visualisation"][:lighting :rendering :run :statistics]
[1:29:16][Make LightingTest() position our debug sampler below the floor][:lighting :rendering :statistics]
[1:30:22][See that our sampler is shooting rays in the wrong direction][:"debug visualisation" :lighting :rendering :run :statistics]
[1:31:16][Recolour our rays in ComputeLightPropagation(), and visualise the sample coordinate system][:"debug visualisation" :lighting :rendering :statistics]
[1:33:43][See that our coordinate frame is good, but our ability to place samples is not][:"debug visualisation" :lighting :rendering :run :statistics]
[1:34:10][Assert in ComputeLightPropagation() that our tRay is >= 0.01f (i.e. not pointing backwards)][:lighting :rendering]
[1:36:48][:Run the game and hit that assert][:lighting :rendering]
[1:38:15][Make ComputeLightPropagation() test for tMin > ZeroF32_4x() when setting tValid][:lighting :rendering]
[1:38:43][See that it looks much better, noting that we got a lot brighter when turning off angular falloff][:"debug visualisation" :lighting :rendering :run :statistics]
[1:42:39][Enable GenerateLightingPattern() to produce an additional unweighted sampling pattern for comparison][:lighting :rendering :statistics]
[1:53:10][Introduce TestFunc() for GenerateLightingPattern() to call][:lighting :rendering :statistics]
[1:54:56][Step through to GenerateLightingPattern() and inspect our MinTestAvg and MaxTestAvg to see that they differ a lot][:lighting :rendering :run :statistics]
[1:55:32][Fix GenerateLightingPattern() to use F32Min rather than 0.0f][:lighting :rendering :statistics]
[1:55:47][Step back through to GenerateLightingPattern() and inspect our MinTestAvg and MaxTestAvg to see that they still differ a lot][:lighting :rendering :run :statistics]
[1:56:29][Enable GenerateWhiteNoiseSamples to produce a biased sampling pattern][:lighting :rendering :statistics]
[1:58:39][Step through to GenerateLightingPattern() and inspect our averages to see that they differ differently][:lighting :rendering :run :statistics]
[2:00:24][Q&A][:speech]
[2:01:35][@insobot][Blow's avatar looks exactly like him!]
[2:02:25][@vateferfout][Q: Hi, not really an on-topic question, but you said you'd talk about some tidbits concerning the SIMD union type]
[2:03:02][@Zilarrezko][Q: How are you feeling on the progress of the :lighting so far?][:rendering]
[2:03:11][@hholst80][Q: Are there any libraries available that would help with just the :lighting stuff you're working on right now? It seems fairly involved and require some R&D from the developer's part][:library :rendering]
[2:03:23][@gprincip][Q: Why are you not sure about GPU'ing light? Do you think that it might not increase FPS?][:hardware :lighting :rendering]
[2:04:49][@cicero743][Q: What are your dislike on Windows 10? Some people complain about it because of their hatred against Microsoft regardless how good to product is but I feel like they mixed a lot of messy stuff after 8 and 8.1. What are the things you'd like them to fix?]
[2:07:21][@blackburn1911][Q: How many hours / day are you programming?]
[2:07:38][@Zilarrezko][Q: Do you think we will be able to keep the :lighting, at least to this complexity or even method, on the Raspberry Pi?][:rendering]
[2:07:52][@jim0_o][Q: What level are intrinsics defined, are intrinsic CPU vendor specific or architecture specific? Will we/you need to make AMD/Intel specific Intrinsics or x86/x64 ? (or is it defined on a different level?)]
[2:08:30][@alexkelbo][Q: I understand you switched from AMD to NVIDIA. Any specific reason?][:hardware]
[2:08:49][@thebaker__][Q: how much longer do you expect to spend on :lighting?][:rendering]
[2:08:53][@iwrestledabeer][Q: Sorry for an off-topic question, I'm pretty far behind. I'm curious if you have already implemented the swapping function or macro. How would you avoid using templates for this?]
[2:09:15][Using the SIMD union type to issue instructions to particular units[ref
    site=Intel
    page="Intel Intrinsics Guide"
    url=https://software.intel.com/sites/landingpage/IntrinsicsGuide/]][:hardware :optimisation :speech]
[2:17:25][@sz19][Q: What are the specs of your current dev machine?][:trivia]
[2:17:58][@lorefyr][Q: In your opinion, what are low hanging fruits the UNIX / Linux world could or should tackle to become more competitive with Windows, from a usability perspective?]
[2:21:02][@elfeck][Q: Can you explain why you use f32 instead of f64 (double)?]
[2:21:56][@n30sh4d0w][Q: Is this something that could cause a stack overflow? Or related to it?]
[2:22:24][@n30sh4d0w][Q: Would what you are talking about unions be related to overflow of variables (or "stack overflow") if you did things wrong? I was asking because I was curious what error codes you could look for for this problem]
[2:24:02][Close it down][:speech]
[/video]
