[video output=day388 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Successful Multisampled Depth-Peeling" vod_platform=youtube id=qXS_GHgbNbU annotator=Miblo]
[0:12][Thank @serge_rgb for fixing the offset bug in ~Milton, and determine to try CodeXL]
[1:35][Try to run the game in CodeXL]
[6:13][Inspect the history of OpenGL function calls]
[7:26][Try without success to continue to the next frame, and determine to update the machine]
[10:37][Read @Mox's bug report on the depth buffer being disabled in ResolveMultisample()[ref
    site="Handmade Hero Forums"
    page="Day 387 Bug Handmade resolve framebuffer"
    url="https://hero.handmade.network/forums/code-discussion/t/2399-%5Bday_387_bug%5D_handmade_resolve_framebuffer"]]
[16:30][handmade_opengl.cpp: Reduce the DepthThreshold in CompileResolveMultisample()]
[19:37][handmade_opengl.cpp: Prevent ResolveMultisample() from disabling the entire depth buffer in favour of disabling depth testing only, and leaving depth writes on]
[20:56][Compare our code with @Mox's report[ref
    site="Handmade Hero Forums"
    page="Day 387 Bug Handmade resolve framebuffer"
    url="https://hero.handmade.network/forums/code-discussion/t/2399-%5Bday_387_bug%5D_handmade_resolve_framebuffer"]]
[23:31][Run the game and try to toggle on multisampling]
[24:47][win32_handmade.cpp: Switch to 960x540 and enable multisampling by default]
[26:08][Run the game and inspect a screenshot to confirm that we get 1-to-2 pixels]
[27:26][Run the game and point out our diagonal lines in the ground cube primitives]
[28:32][handmade_opengl.cpp: Make CompileResolveMultisample() use all the samples and run the game to see that we're in a better place]
[31:03][handmade_opengl.cpp: Try to restore the depth range testing in CompileResolveMultisample()]
[32:44][Run the game to see some artifacts]
[33:40][handmade_opengl.cpp: Revert CompileResolveMultisample() to set, but not only pick from, the minimum depth and run the game to see some artifacts during the peel where the primitives abut]
[36:35][Consider the fact that we don't actually need multisampling here]
[39:03][handmade_opengl.cpp: Try to make CompileResolveMultisample() only pick the minimum depth again]
[40:12][handmade_opengl.cpp: Try turning off sRGB in CompileResolveMultisample() and run the game to determine that it is more correct with sRGB on]
[41:34][Blackboard: Producing a premultiplied colour from a percent-coverage value of any given pixel in a primitive]
[43:49][Blackboard: Storing each of those colour values in the peel]
[45:48][handmade_opengl.cpp: Read how CompilePeelComposite() handles sRGB]
[47:30][Blackboard: Considering the case with two triangles touching, that have the same colour value]
[49:06][handmade_opengl.cpp: Consider the possibility that CompileResolveMultisample() is computing slightly different sample positions]
[53:12][handmade_opengl.cpp: Make CompileResolveMultisample() set the InvSampleCount up front and add in that colour every time]
[53:58][Run the game to see that it looks basically the same]
[55:11][Wonder if we necessarily know how many samples there are in a pixel]
[56:49][handmade_opengl.cpp: Double-check the CompilePeelComposite() code, and wonder if the framebuffer's recording of Z values couldn't also be involved in this]
[58:20][handmade_opengl.cpp: Make CreateFramebuffer() use GL_DEPTH_COMPONENT32F in an effort to avoid quantisation errors]
[59:09][Run the game to see no effect]
[1:00:16][Closely inspect the diagonal artifact across the hero's face, and consider why that occurs]
[1:07:07][Consult the documentation on glSampleCoverage[ref
    site="Khronos"
    page="glSampleCoverage"
    url="https://www.khronos.org/registry/OpenGL-Refpages/es1.1/xhtml/glSampleCoverage.xml"]]
[1:09:25][Read about Fixed-Function Primitive Assembly and Rasterization in the OpenGL 4.5 (Core Profile) spec[ref
    site="OpenGL"
    page="OpenGL 4.5 (Core Profile)"
    url="https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf"]]
[1:15:31][handmade_opengl.cpp: Disable multisampling, try to make OpenGLRenderCommands() enable GL_POLYGON_SMOOTH, run the game and see no smoothing]
[1:20:21][Read about Pixel Ownership Test in the OpenGL 4.5 (Core Profile) spec[ref
    site="OpenGL"
    page="OpenGL 4.5 (Core Profile)"
    url="https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf"]]
[1:22:12][Run the game and wonder if the summation from depth peel to depth peel is not correct]
[1:23:22][handmade_opengl.cpp: Try to make CompileResolveMultisample() hard set the alpha to 1, run the game and still see the summation error across the primitive boundary]
[1:25:35][Blackboard: How the alpha summation is wrong]
[1:27:44][handmade_opengl.cpp: Make CompileResolveMultisample() sum all the colours starting from the furthest depth]
[1:28:58][Run the game to see artifacts where trees overlap, but not at the triangle primitive boundaries]
[1:31:16][handmade_opengl.cpp: Set an AlphaThreshold in OpenGLRenderCommands() and run the game to see how that affects it]
[1:34:08][handmade_opengl.cpp: Try preventing CompileResolveMultisample() from performing centroid sampling, and run the game to see that it's a lot nicer]
[1:36:33][handmade_opengl.cpp: Fully remove centroid sampling and run the game to see that it's nice and smooth, but subtly wrong at some edges]
[1:41:14][Blackboard: Multisampling colours with low alpha values]
[1:43:18][handmade_opengl.cpp: Make CompileResolveMultisample() track both the min and max depth and halve that the range]
[1:44:06][Run the game to see a lot less artifacts]
[1:44:46][handmade_opengl.cpp: Make OpenGLRenderCommands() set AlphaThreshold to 0, run the game and now only see artifacts during peeling]
[1:48:26][Q&A][:speech]
[1:48:51][Close the "GLSL version / extension for sampler2DMS" and "Two small compiler warnings VS17" issues[ref
    site="GitHub"
    page="HandmadeHero/cpp Issues"
    url="https://github.com/HandmadeHero/cpp/issues"]]
[1:51:25][Run the game to see that all is good]
[1:52:12][@uplinkcoder][gl_polygon_smooth is not supported by many modern cards]
[1:52:35][@cubercaleb][What about the type cast?]
[1:52:56][@nrec_][Hi, I'm new here, sorry if this has been asked before. Looks like you're doing an engine right now. Any idea about what the game would be?]
[1:56:42][@wasenabled][As it appears you are nearing the end of the main engine dev, will you be adding in the non-Win32 layers too, or have others already done those?]
[1:59:05][Wrap it up for the day with a reflection on how well the multisampling works, and thanks to @mtsmox for reporting the bug][:speech]
[/video]
