Original Post
Hello, I'm looking into deferred shading to light up my scenes and I have now come to the time where I want to use different materials for my objects. In a forward renderer, this is quite straight-forward since every object is shaded individually and I can just pass needed material parameters to the shader that is used. But when doing deferred shading it gets a little complicated how to transfer the material attributes into the light phase efficiently. I first thought of storing a material ID in a texture together with some variables used for the material and then do dynamic branching in the light shader. But this felt a bit ugly and I'm probably bound to run out of instructions sooner or later. And in my experience dynamic branching in pixel shaders is very costly. I read a previous topic on GameDev touching this subject: http://www.gamedev.net/community/forums/topic.asp?topic_id=396527&PageSize=25&WhichPage=1 AndyTX says here:
Quote:He's talking about dynamic branching in the light shader, but what does it mean that the branching is "highly coherent" and why is this a minimal performance hit? Excuse me if I'm stupid here :P I also read about deferred shading in S.T.A.L.K.E.R. (in GPU Gems 2) and as I understand it they store their materials in a 3D texture and do texture lookups in the light shader. Andy TX about this:
As I mentioned, the branching is highly coherent and so the performance hit is minimal.
Quote:Once again sorry if I'm stupid, but how exactly is this done without multiple passes? I guess that the BRDF parameters are the ones to use in my lighting calculation, and these change every time I change the lighting or change the objects position/orientation or camera position/angle. So isn't these parameters written to a texture during the geometry phase as with depth, normal and diffuse RGB? If so, I can only fit so much info in my textures - I'm on my 4th and final texture to use in MRT geometry pass (plus some free space in the other textures). When and how is this 3D texture holding material attributes filled and how does this eliminate the need for branching...? Thanks!
Furthermore another option (that I believe they used in STALKER) is to put your BRDFs into a 3D texture and use the material ID to choose the slice. This is a really easy, really high performance and quite flexable way of doing different materials without branching or multiple passes.