• Advertisement
Sign in to follow this  

Lighting the back of triangle

This topic is 2149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Hello Julian

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement