Sign in to follow this  
Talyrond

Lighting the back of triangle

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
[quote name='Talyrond' timestamp='1333483109' post='4927984']
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
[/quote]
With OpenGL you can get the fixed function per vertex lighting to affect both sides if you use [i]GL_LIGHT_MODEL_TWO_SIDE[/i]
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
[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).
[/quote]

In DirectX (10 at least) you can use the semantic SV_IsFrontFace in the pixel shader input :
[code]

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
// ....
}
[/code]

Maybe you can find something equivalent for OpenGL ?

Nico

Share this post


Link to post
Share on other sites
[quote name='NicoLaCrevette' timestamp='1333550060' post='4928208']
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).
[/quote]

In DirectX (10 at least) you can use the semantic SV_IsFrontFace in the pixel shader input :
[code]

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
// ....
}
[/code]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this