Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How to use a few shading functions together with deferred rendering (for example some objects are shaded based on a lighting equation, other get a fixed color) ? I draw a full screen quad when shading (later I want to add optimizations for point lights). I have some idea how to solve that problem: during a gbuffer stage a shading function id should be saved in one of the render targets. Then we can do something like this:

if(id == 0)
{
    fragColor = shadingFun0(...);
}
else
{
    fragColor = shadingFun1(...);
}

What do you think about that ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I believe having a lot of ifs in a fragment shader could have a serious performance impact. You could probably use the stencil buffer for this purpose.

Or save up to 4 light types in the color channels of a separate rendertarget and do this: fragColor = shadingFun0(...) * texColor.r + shadingFun1(...) * texColor.b and so on.

Or as a hack, you can manipulate the normals of some objects, so the light equation returns a different color.

Or just do multiple passes, one for each light type. So one deferred shading pass, and then you just draw the other objects on the resulting FBO (keeping the depth buffer, I guess).

Also I'm not sure about this, but isn't the whole point of using deferred shading that you can use the best lighting model for everything?

share|improve this answer
    
I agree. Not only is branching like that defeating the point, it's probably a lot less efficient. –  Boreal Jan 31 '13 at 22:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.