Hi,
In DirectX the back of a triangle is drawn black, but I get the impression that in OpenGL this is not the case and both sides will be lit. I am not talking about Culling, no culling is assumed here.
So in other words if I want both side of a triangle to be lit in DirectX I need to draw two triangles wound in opposite directions and of course with normal’s pointing away from each other (need to cull in opposite directions as well).
In OpenGL this is not necessary, I am I right in my assumptions?
Thanks
Julian
Lighting the back of triangle
Hi,
In DirectX the back of a triangle is drawn black, but I get the impression that in OpenGL this is not the case and both sides will be lit. I am not talking about Culling, no culling is assumed here.
So in other words if I want both side of a triangle to be lit in DirectX I need to draw two triangles wound in opposite directions and of course with normal’s pointing away from each other (need to cull in opposite directions as well).
In OpenGL this is not necessary, I am I right in my assumptions?
Thanks
Julian
With OpenGL you can get the fixed function per vertex lighting to affect both sides if you use GL_LIGHT_MODEL_TWO_SIDE
it is however fairly inefficient and might actually cause the hardware to draw two triangles on older hardware. (and possibly modern hardware aswell depending on the driver quality)
If you are using modern Direct3D or OpenGL you can have your pixel/fragmentshader invert the normals for any backfacing triangles that you want lit.
Hello Julian
In DirectX (10 at least) you can use the semantic SV_IsFrontFace in the pixel shader input :
Maybe you can find something equivalent for OpenGL ?
Nico
So in other words if I want both side of a triangle to be lit in DirectX I need to draw two triangles wound in opposite directions and of course with normal’s pointing away from each other (need to cull in opposite directions as well).
In DirectX (10 at least) you can use the semantic SV_IsFrontFace in the pixel shader input :
float4 PS(PS_INPUT input,bool isFrontFace : SV_IsFrontFace) : SV_Target
{
float3 normal=normalize(input.vNormalWorld);
if (!isFrontFace) normal*=-1.0f; // rendering the back face, so I invert the normal
// ....
}
Maybe you can find something equivalent for OpenGL ?
Nico
Hello Julian
[quote name='Talyrond' timestamp='1333483109' post='4927984']
So in other words if I want both side of a triangle to be lit in DirectX I need to draw two triangles wound in opposite directions and of course with normal’s pointing away from each other (need to cull in opposite directions as well).
In DirectX (10 at least) you can use the semantic SV_IsFrontFace in the pixel shader input :
float4 PS(PS_INPUT input,bool isFrontFace : SV_IsFrontFace) : SV_Target
{
float3 normal=normalize(input.vNormalWorld);
if (!isFrontFace) normal*=-1.0f; // rendering the back face, so I invert the normal
// ....
}
Maybe you can find something equivalent for OpenGL ?
Nico
[/quote]
gl_FrontFacing
http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_FrontFacing.xml
same thing, also an input variable for the pixel/fragment shader
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement