What is the best way to draw unlit objects with deferred? Like skybox, particles or just glowing objects? I thought about mask in alpha channel, check it in light pass and just set diffuse color but it won't work with light blending. My second idea was stencil buffer with pass after light pass that only fill unlit space. But switching pso (dx12) only for color copy doesn't sound like a good idea. And of course pass only for unlit objects after light pass, but I don't want to create another list only for this (and again, i have to switch pso).
1 Answer
Typically in a deferred engine, you would render unlit objects directly to the color buffer, bypassing the lighting system entirely. You would likely also output zeroes to the G-buffer so that deferred lights don't add anything to those pixels (and possibly also mark them in the stencil buffer, to avoid running the lighting shaders on them, for efficiency).
Don't worry about switching PSOs for this. I'm guessing you're worried about the performance, but it's not a big deal. Game engines typically switch PSOs (or switch shaders, in DX11/GL) hundreds or thousands of times per frame. Switching a couple of times for an extra color rendering pass isn't even a blip on the radar.
However, if you want to really simplify your code (possibly at the expense of performance), you could just bind the color buffer together with your G-buffers and render to it all the time, as if it were an extra G-buffer. Ordinary deferred shaders would output zero to it, while unlit objects would output their color to it.
-
$\begingroup$ Thanks for your reply. Idea with writing directly to color buffer sounds great. I will give it a try. $\endgroup$– DeragCommented Apr 14, 2016 at 5:13