Author Topic: disabled culling and normals in shader  (Read 908 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
disabled culling and normals in shader
« 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: disabled culling and normals in shader
« Reply #1 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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: disabled culling and normals in shader
« Reply #2 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

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: disabled culling and normals in shader
« Reply #3 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...?
« Last Edit: June 21, 2012, 09:27:31 pm by Thomas. »