Jump to content
  • Advertisement
Sign in to follow this  
CDProp

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

This topic is 2803 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!