2 Sided Lighting?

Hi–

Im new to Unity but have used similar tools for visualization (Vizard) and have a question about the Unity lighting model. In Vizard, one can set the OpenGL lighting model to two sided. This tells the renderer to light both sides of any given mesh when backside culling is disabled. (Those familiar with CAD applications may note that this is standard stuff in those applications). This is important when visualizing non-solid geometry and surfaces.

I’ve read all the documentation about shaders, but the only params I’ve seen for Lighting is On|Off.

Can Unity be configured to use a two-sided lighting model? For the OpenGL’ers out there, I’m looking for something that will enable this call:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

Thanks again,
PP

is that something a shader could do? would be my first guess.

You can’t turn this on globally AFAIK, but you can use 2-sided shaders that are included with Unity, or, custom write your own 2-sided shader.

If you wish to make a shader “two-sided”, you can create a copy of the shader, open it in MonoDevelop and add the “Cull OFF” line like this:

SubShader {
Tags {“Queue”=“AlphaTest” “IgnoreProjector”=“True” “RenderType”=“TransparentCutout”}
LOD 400

Cull OFF

CGPROGRAM
blah, blah, blah, blah

Thanks for the replies.

Im sure a shader can do this, but then that will require applying the shader to thousands of parts/models.

I am aware of how to turn off culling, but that only solves half of the problem; since the surface normals may face “inward,” the lighting/shading is inverted. I can post a picture if you’d like.

Are there any “global” renderer cfg files that can be tweaked? While I’m aware that all target platforms may not run OGL, it seems odd that this type of functionality would be delegated to a shader.

Thx
PP

The shaders would need to support double-sided lighting, and it would have to work on all platforms to make it a global switch. That’s not the reality right now.

I can see it’s a useful thing to have, especially for non-games where you are not too concerned with performance, since double sided geometry can impact that quite a bit. Probably the best solution is having an option on model import to create double sided triangles, with normals facing the right direction, and then running a script to do that on the whole project.

Thanks Kaspar–much appreciated.

Can you recommend a script or shader that does this? This would have to be a vertex shader, correct?

Thanks again,
PP

FWIW for anyone interested this issue was solved using this sample code:
http://en.wikibooks.org/wiki/GLSL_Programming/Unity/Two-Sided_Surfaces

This was actually only half of the solution…since the shader wont work unless you force OpenGL on Windows! Here is a link that describes how to force OGL:
http://en.wikibooks.org/wiki/GLSL_Programming/Unity

“First, Windows users have to use the command-line argument -force-opengl [1] when starting Unity in order to be able to use GLSL shaders; for example, by changing the Target setting in the properties of the desktop icon to: “C:\Program Files\Unity\Editor\Unity.exe” -force-opengl . (On MacOS X, OpenGL and therefore GLSL is used by default.) Note that GLSL shaders cannot be used in Unity applications running in web browser on Windows.”

Kaspar, if your are reading this, folks that use Unity in training, visualization, and simulation rely on sometimes crummy tessellated CAD models that they have no means to fix. Including a simple option to enable 2-sided shading and lighting would be a good thing for Unity.