[video output=day317 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Alpha Blending Multiple Render Targets" vod_platform=youtube id=Wv2IAKs7W0A annotator=Miblo] [1:06][Run the game and show our current situation with render targets] [2:56][handmade_entity.cpp: Make UpdateAndRenderEntities() create two different ClipRects for the alpha and normal floors] [6:08][Run the game and see that the alpha stuff is gone] [6:53][Consider ways of using multiple render targets] [9:28][handmade_render.cpp: Add a RenderGroupEntryType_blend_render_target in RenderCommandsToBitmap() and introduce BlendRenderTarget()] [14:36][handmade_render.cpp: Implement BlendRenderTarget() based on DrawRectangle()] [24:44][handmade_render.cpp: Introduce Pack4x8()] [26:00][handmade_render.cpp: Continue implementing BlendRenderTarget(), making it do gamma properly] [27:27][handmade_render_group.h: Add RenderGroupEntryType_blend_render_target to the render_group_entry_type enum and introduce render_entry_blend_render_target struct] [29:14][Run the game and see that it does nothing] [29:33][handmade_render.cpp: Make RenderCommandsToBitmap() clear everyone] [31:55][handmade_render_group.cpp: Introduce PushBlendRenderTarget() based on PushClipRect(), which will do the composite] [39:39][handmade_entity.cpp: Make UpdateAndRenderEntities() call PushBlendRenderTarget()] [41:30][Debugger: Run the game and crash in Win32CompleteAllWork()] [41:51][build.bat: Switch to -Od, run the game and crash in BlendRenderTarget()] [42:33][handmade_entity.cpp: Make UpdateAndRenderEntities() use AlphaFloorRenderTarget and pass it to BlendRenderTarget()] [43:07][build.bat: Switch to -O2, run the game and see how slowly the game now runs] [44:16][Debugger: Step through BlendRenderTarget() and investigate what's happening] [44:51][handmade_render.cpp: Make BlendRenderTarget() correctly set the DestColor and Result] [45:32][Run the game, see no alpha blending happening and investigate why] [46:40][handmade_render.cpp: Try making BlendRenderTarget() hardcode the Alpha to 0.5f] [46:57][Run the game and see that the Alpha is not taking effect] [48:01][build.bat: Switch to -Od, step in to BlendRenderTarget() and see what happens when we have a source pixel with something in it] [49:23][handmade_entity.cpp: Remove the transient_clip_rect from UpdateAndRenderEntities() and make it manually set the CurrentClipRect] [50:12][Run the game and see the prettiness before switching to -O2] [50:45][Run the game and marvel at the indescribable cacophony of epileptic color][quote 513] [51:36][handmade_render.cpp: Make BlendRenderTarget() use SRGB255ToLinear1() and Linear1ToSRGB255()] [53:51][Run the game and again see the sparkly] [54:11][handmade_render.cpp: Prevent Pack4x8() from doing the multiply] [54:31][Run the game and see that we're getting closer to being correct] [54:47][handmade_render.cpp: Make BlendRenderTarget() use the correct Alpha] [56:18][handmade_entity.cpp: Make UpdateAndRenderEntities() set TestAlpha as a single r32 rather than an array of them] [58:40]["I love how it can't ever tell you any values in release mode"][quote 514] [58:46][Debugger: Step into UpdateAndRenderEntities() and investigate how TestAlpha got to be set to 1.0f] [1:01:42][handmade_entity.cpp: Make UpdateAndRenderEntities() pass FadeTopEndZ and FadeTopStartZ to TestAlpha() in the opposite order] [1:01:58][build.bat: Switch to -O2, run the game and see the alpha blending working beautifully] [1:03:12][handmade_render.cpp: Make RenderCommandsToBitmap() clear both the MaxRenderTargetIndex and the previous TargetIndex] [1:03:41][Run the game and see that now it looks like we're good] [1:04:00][Note that the clear is clearing at 1.0f alpha, and that it has to actually clear, not blend] [1:04:46][Q&A][:speech] [1:05:57][@Kknewkles][Giger / Lovecraft-themed Handmade Hero DLC confirmed?] [1:06:08][@soysaucethekid][Are you writing to the second buffer all the time? If so, is it possible to only use when you need it (like during the transitions)?] [1:06:37][handmade_entity.cpp: Make UpdateAndRenderEntities() only do the multiple buffers stuff if the alpha is enabled] [1:09:25][@pseudonym73][How does a limbless child "limp along", exactly?] [1:09:34][@inquarry][How many floors can this code support? I envision a tall tower or stairwell, peering down 20 or so floors and seeing NPCs acting as normal. Was that your intent?] [1:10:56][@Kknewkles][How do you use trace files to debug? Someone trying my game prototype had a crash and sent me a (95MB) dump file, since you once said it's helpful. I don't doubt that, but what do you do with the damn thing?] [1:13:39][Wrap it up][:speech] [/video]