disabled culling and normals in shader

Started by Thomas., May 25, 2012, 01:35:03 PM

Previous topic - Next topic

Thomas.

I have problem with objects without culling. I'm using shader for calculating per-pixel lighting. When I disable culling, normals are still same, so lighting is "bad" from other side. Is there any simple and fast solution? or is better to use two triangle for each side?

EgonOlsen

Quote from: Thomas. on May 25, 2012, 01:35:03 PM
Is there any simple and fast solution? or is better to use two triangle for each side?
None that i know of. You could invert the normal in the shader, but i've no idea how to detect if this is needed.

Thomas.

OK, so I will copy triangles to both side, that will be the simplest solution for me

Thomas.

#3
I solved the problem. For calculating dot product of normal and light direction is using max from dot and 0 for "dark to light" shading

max(dot(normal, lightVector), 0.0);

If you replace above mentioned by this one, lighting is good from both side... get "light - dark - light" shading

abs(dot(normal, lightVector));

EDIT: this of course not working in camera - plane - light case. In theory, it will probably needs camera-vertex dot and check it with normal-light dot...?