www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on May 25, 2012, 01:35:03 pm

Title: disabled culling and normals in shader
Post by: Thomas. on May 25, 2012, 01:35:03 pm
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?
Title: Re: disabled culling and normals in shader
Post by: EgonOlsen on May 25, 2012, 01:50:28 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.
Title: Re: disabled culling and normals in shader
Post by: Thomas. on May 25, 2012, 02:07:33 pm
OK, so I will copy triangles to both side, that will be the simplest solution for me
Title: Re: disabled culling and normals in shader
Post by: Thomas. on June 21, 2012, 08:42:04 pm
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

Code: [Select]
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

Code: [Select]
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...?