[video output=day439 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Testing Better Entropy" vod_platform=youtube id=14UGyk8N3p4 annotator=Miblo]
[0:01][Recap and set the stage for the day][:speech]
[0:49][Hemisphere Integration][:blackboard :lighting :rendering :statistics]
[12:38][Our light reception function][:blackboard :lighting :rendering :statistics]
[17:09][Weighted sampling, as a way to optimise out the multiplication of a weighting coefficient][:blackboard :lighting :rendering :statistics]
[29:18][Writing the bias into the sampling equation][:blackboard :lighting :rendering :statistics]
[33:10][Review GenerateLightingPattern() from last stream][:lighting :rendering :research :statistics]
[33:59][Make GenerateLightingPattern() take a much greater number of samples, to try and see if it converges][:lighting :rendering :statistics]
[34:50][:Run the game to see that it takes too long to compute][:lighting :rendering :statistics]
[35:56][Make GenerateLightingPattern() take not quite that many samples][:lighting :rendering :statistics]
[36:10][Step in to GenerateLightingPattern() and inspect the test averages][:lighting :rendering :run :statistics]
[36:49][Make GenerateLightingPattern() perform fewer tests and take more samples][:lighting :rendering :statistics]
[37:12][Step in to GenerateLightingPattern() and inspect the test averages][:lighting :rendering :run :statistics]
[37:23][Further increase the sample count and lower the test count in GenerateLightingPattern()][:lighting :rendering :statistics]
[37:48][Step in to GenerateLightingPattern() and inspect the test averages][:lighting :rendering :run :statistics]
[38:00][Increase the test count in GenerateLightingPattern()][:lighting :rendering :statistics]
[38:16][Step in to GenerateLightingPattern() and inspect the test averages, to find that we are starting to converge][:lighting :rendering :run :statistics]
[38:49][Consider replacing xorshift with PCG, specifically its notion of k-Dimensional Equidistribution[ref
    author="Melissa E. O'Neill"
    title="PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation"
    url=http://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf]][:prng :research]
[44:46][Determine to plot our random sampling points][:lighting :prng :rendering :speech :statistics]
[46:20][:Run the game to see our sample points][:"debug visualisation" :lighting :rendering :statistics]
[46:37][Enable LightingTest() to draw a random set of sampling points][:lighting :prng :rendering :statistics]
[49:41][:Run the game to see our random sample points][:"debug visualisation" :lighting :prng :rendering :statistics]
[50:33][:Research sphere point picking[ref
    site="Wolfram MathWorld"
    page="Sphere Point Picking"
    url=http://mathworld.wolfram.com/SpherePointPicking.html]][:prng :statistics]
[53:10][Implement Marsaglia's method for uniform point picking on a sphere[ref
    site="Wolfram MathWorld"
    page="Sphere Point Picking"
    url=http://mathworld.wolfram.com/SpherePointPicking.html][ref
        site=Wikipedia
        page="George Marsaglia"
        url=https://en.wikipedia.org/wiki/George_Marsaglia]][:prng :statistics]
[56:38][:Run the game to check out Marsaglia's sampling][:"debug visualisation" :lighting :prng :rendering :statistics]
[57:12][Toggle between Marsaglia's method and our full random sampling in LightingTest()][:lighting :prng :rendering :statistics]
[58:04][:Run the game to check out the two sampling patterns][:"debug visualisation" :lighting :prng :rendering :statistics]
[58:47][Modify Marsaglia's method in LightingTest() to sample only the upper hemisphere][:lighting :prng :rendering :statistics]
[59:52][:Run the game to check out the two hemisphere sampling patterns][:"debug visualisation" :lighting :prng :rendering :statistics]
[1:00:52][Introduce random_series_pcg and versions of RandomNextU32(), RandomUnilateral() and RandomBilateral() that take this struct[ref
    author="Melissa E. O'Neill"
    title="PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation"
    url=http://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf]][:prng]
[1:10:40][Praise the compiler for figuring out that we'd never pass the check in Marsaglia's sampling routine, thus raising the "unreachable code" warning]
[1:11:25][Determine to enable the random_series_pcg version of RandomNextU32() to perform xorshift[ref
    author="Melissa E. O'Neill"
    title="PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation"
    url=http://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf][ref
        site="PCG, A Better Random Number Generator"
        page="Download the PCG Library"
        url=http://www.pcg-random.org/download.html]][:prng :research]
[1:19:36][Try to check out the example PCG code, but encounter a hang in File Explorer when clicking "New"][:prng :rant]
[1:22:46][Read through pcg_basic.c in conjunction with Melissa E. O'Neill's PCG paper[ref
    author="Melissa E. O'Neill"
    title="PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation"
    url=http://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf] and Pierre L'Ecuyer's 'Tables of linear congruential generators'[ref
    author="Pierre L'Ecuyer"
    title="Tables of linear congruential generators of different sizes and good lattice structure"
    url=https://www.semanticscholar.org/paper/Tables-of-linear-congruential-generators-of-sizes-L'Ecuyer/0c76f5adb2e595bf21484745773f7aaafbf59cd1] with a view to understanding why the example code uses rng->inc or'd with 1 in the LCG update step][:prng :research]
[1:30:08][Consult Wikipedia's article 'Linear congruential generator'[ref
    site=Wikipedia
    page="Linear congruential generator"
    url=https://en.wikipedia.org/wiki/Linear_congruential_generator] to discover that O'Neill must be using Knuth's LCG style][:prng :research]
[1:32:28][Enable the random_series_pcg version of RandomNextU32() to perform the LCG update step, augmenting random_series_pcg to contain a Selector][:prng]
[1:35:02][Introduce RandomSeedPCG() for LightingTest() to use][:prng]
[1:37:01][:Run the game to see if we get any better random results][:prng :statistics]
[1:38:05][Fix RandomNextU32() to correctly cast the entire PreRotate computation][:prng]
[1:38:31][:Run the game to compare the PCG and Xorshift random sampling patterns][:"debug visualisation" :lighting :prng :rendering :statistics]
[1:39:23][Make LightingTest() use a different random series for each axis][:lighting :prng :rendering :statistics]
[1:41:22][:Run the game to determine that the non-PCG random sampling looks fine][:"debug visualisation" :lighting :prng :rendering :statistics]
[1:42:21][Q&A][:speech]
[1:43:02][@lokathor][Q: You can't have an even number as the Selector because then the 1s-bit would never flip and your period would get cut down a few orders of magnitude. The paper goes over that at some point if I recall correctly][:prng]
[1:43:30][@vaualbus][Q: In the random series when you write the state part there is a bug: it should be (incr << 1) | 1][:prng]
[1:43:36][Fix RandomSeedPCG() to correctly shift the Selector][:prng]
[1:43:56][:Run the game to see no significant difference][:"debug visualisation" :lighting :prng :rendering :statistics]
[1:45:15][@lokathor][Q: The basic PCG32 you're using will only be k-dimensionally equidistributed for simple (u32,u32) tuples. Each u32 will appear 2^32 times within the 2^64 period. You'll need PCG64 or an extension array if you want k-d equi for v3 or more. However, it probably doesn't actually matter for your v3 generation case here, because you're unlikely to actually see the generator loop around. Even at one v3 generated per nanosecond (extremely generous), it'd take \~195 years to see a loop][:prng]
[1:45:51][@thejimjames40][Q: What is your opinion on event systems? And how would you implement one?]
[1:46:43][@lifeam1][Q: Is there a way that a slack channel can be set up that way us newbies can catch up and have a place to ask questions as I am finding it hard to keep up with the earlier videos without a lot of side researching]
[1:47:21][@postalrat][Q: What are sampling and for what? Missed out on that part]
[1:47:53][@internal_static_void_][Q: So why opt for a PCG or LCG generator rather than just hashing the time for a random number?][:prng]
[1:49:17][@thejimjames40][@handmade_hero An event system for communication between interacting systems]
[1:49:50][@schoenhs][Q: In Monte Carlo estimates usually error scales like 1/sqrt(samples). For 1024 samples one expects error of order 0.03 and for 65k one expects error of order 0.003. It therefore seems like the error you're seeing is pretty reasonable, or am I misunderstanding?][:prng]
[1:50:22][@mindrage][Q: What would you consider the most performant RNG despite the accuracy?]
[1:51:11][@bigmofo1][Q: What will you work on tomorrow?]
[1:52:15][Generating blue noise cos(𝜃) distributed sampling points on a disc, for projection up to its hemisphere][:blackboard :statistics]
[1:57:30][@staythirsty90][Q: Can I see the current state of the :lighting / game?][:rendering]
[1:57:37][Show the :lighting in the game][:rendering :run]
[1:59:04][@jamoflaw][Q: Is there an intention to support shadows from the point lights?][:lighting :rendering]
[1:59:56][@staythirsty90][Q: Will there be any raymarching / volumetric fluid stuff?]
[2:00:21][We are out of questions][:speech]
[/video]
