Is there a trick to getting two-sided lighting to work?

Started by
4 comments, last by CDProp 13 years, 5 months ago
I have some models that I have to use, which contain a lot of double-sided polygons. I want to enable double-sided lighting, so that the side facing the light looks lit, and the side facing away looks shadowed.

I'm enabling GL_LIGHT_MODEL_TWO_SIDE, but that doesn't seem to work. Just like before, both sides look lit/dark depending on where the front face is oriented with respect to the incoming light.

Is there some other setting that needs to be enabled as well?

I'm working with a complex scene graph, where each node has its own OpenGL state, and parent nodes can override child nodes, and all sorts of crazy crap like that. So, it's really difficult for me to verify that GL_LIGHT_MODEL_TWO_SIDE is indeed set at the time that the draw call is made. But, before I dig into that, I thought I'd just check real quick to make sure there isn't something simple that I'm missing.

If all else fails, I guess I'll just write my own shader. Bonus question: I know the FFP stuff was deprecated. Does that mean we'll lose access to all of those built-in uniforms like gl_Vertex, gl_Normal, gl_ModelViewMatrix and so on? I've always liked having access to those.
Advertisement
Are your triangles wound properly? I've seen people before seem to think that they could have triangles wound incorrectly but enabling two sided lighting would solve their problems, but it doesn't.

All two sided lighting does is flip the normal when rendering the polygon backface. You should get the correct lighting if your normals are pointing correctly out of the front face of the polygon.

Is this the case in your situation? Sorry if I've misunderstood your question.

Quote:
Bonus question: I know the FFP stuff was deprecated. Does that mean we'll lose access to all of those built-in uniforms like gl_Vertex, gl_Normal, gl_ModelViewMatrix and so on? I've always liked having access to those.

Yep those are deprecated as well. You can still access them if you like via a compatibility profile, but I'd recommend just using your own matrices. You can't do a lot of shader techniques without access to separate model and view matrices, which you can't get via the built in matrices.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Yeah, good point. I end up sending down my own matrices for those things anyway. Time to cut the FFP apron strings!

I'm pretty sure the winding order is okay. I haven't noticed any problems before. It's a very simple model. I think something else in the scene graph must be overriding the state that I'm setting, or something.

So, in OpenGL 3+, how does the vertex data get sent to the vertex shader? I know that DirectX 9 does it through vertex declarations that tie vertex data to the shader arguments. Does OpenGL use something similar?


To send the vertex data (known as 'attributes'), you declare a variable in the shader, get its index with glGetAttribLocation, then use glVertexAttribPointer to specify the vbo data that maps to that input variable.

Are you using glLightModel to enable it? You're not trying to use glEnable are you? Are you checking for errors in your program?

I can't think of any other options that would need to be enabled.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Ooh, that's a good question. I'm using an OpenSceneGraph function to set the mode, but I'm not sure if it's smart enough to detect which mode is being set and use the appropriate OpenGL call. I might be using a function that is reserved for glEnable-type calls only.

I'll check and see if they have something special in mind for glLightModel.
Yep, they have a special LightModel class. Thanks!

This topic is closed to new replies.

Advertisement