PDA

View Full Version : deferred rendering and normal mapping



Triangle
01-29-2013, 10:07 AM
During a gbuffer stage I save in textures a depth, normals, diffuse and specular colors, shininnes factors but also
normals from a normal maps (tangent space) and tangent vectors (I can calculate binormal vectors using normals from a normal maps and tangent vectors ).
Only some objects are shaded using normal maps. For objects which don't use normal maps I save in texture vec3(0,0,0) as a normal from a normal map.
Then in a framgent shader I do something like this :


if(a normal vector from a normal map is equal vec3(0,0,0))
{
fragColor = standard_shading_function( some parameters );
}
else
{
fragColor = nm_shading_function( some parameters );
}


'If' statement in a shader program can be expensive but I don't have any other ideas how to solve above problem.
Do you know any better solution ?

tonyo_au
01-29-2013, 04:14 PM
One way to avoid IF tests is is to use some function that has a binary result like this


float ln = length(normal); // will be 0 or 1
fragColor = standard_shading_function(..) * ln + nm_shading_function(..)* (1-ln);


But this is not necessarily faster code.

AFAIK IF tests are bad if a block of compute units (I think they are small like 4x4) don't all take the same path. In your case this will only be on the boundary of objects so practically this may not be so bad.