Sign in to follow this  

Problem with light

This topic is 2833 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

Hi! I got a problem. I made a tunnel using quads. I also got light. I have calculated all the normals etc.. But the problem is light is applied to both sides of my quads. Light should not be applied to the other side of the quad. it shoud just be black. Have tryed to google about this, but i cannot find any solution. It should not be any big problem. I'll show you how i setup the light <code> void lightSetup() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //ljus GLfloat lightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat lightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat lightSpecular[]= {1.0f, 0.0f, 0.0f, 1.0f }; GLfloat lightPosition[] = {3, 3,-4,0}; glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT1, GL_SPECULAR, lightSpecular); glLightfv(GL_LIGHT1, GL_POSITION, lightPosition); glEnable(GL_LIGHTING); glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE) ;//normalisera normalerna glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);//inte 2sidigt glShadeModel(GL_FLAT); //flat eller smooth } </code>

Share this post


Link to post
Share on other sites
Hi!

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);//inte 2sidigt

I would guess you need to set that one to false, as you do NOT want two sided lighting.

Share this post


Link to post
Share on other sites
I think i can explain my problem better now.

Picute 1, the light is outside the tunnel, but does not understand that its outside (still calculats light). But there is a wall in between.
Also the outside has ambient light, but thats just the small problem.

Picture 1: http://img51.imageshack.us/img51/6522/light1s.jpg



The light is inside the tunnel, but it renders the same color on quads on both sides of wall. (Hard to show in one picture, but it does show the same color on both sides of wall)

Picture 2: http://img715.imageshack.us/img715/5466/light2i.jpg

Share this post


Link to post
Share on other sites
Quote:

Picute 1, the light is outside the tunnel, but does not understand that its outside (still calculats light). But there is a wall in between.

This is expected behavior. OpenGL will not perform shadowing for you. If a face is pointed towards the light, it will be lit, regardless of what is in between. If you want to use shadows look up techniques "Shadow Mapping" or "Shadow Volumes".

Regarding the second image:

Quote:

GL_LIGHT_MODEL_TWO_SIDE

params is a single integer or floating-point value that specifies whether one- or two-sided lighting calculations are done for polygons. It has no effect on the lighting calculations for points,lines, or bitmaps. If params is 0 (or 0.0), one-sided lighting is specified, and only the front material parameters are used in the lighting equation. Otherwise, two-sided lighting is specified. In this case, vertices of back-facing polygons are lighted using the back material parameters and have their normals reversed before the lighting equation is evaluated. Vertices of front-facing polygons are always lighted using the front material parameters, with no change to their normals. The initial value is 0.


Sounds like you definitely do want two-sided lighting enabled. If it is enabled and you are still seeing the backside lit than I'm not sure how to explain it. The lighting in your first image looks correct and expected.

Share this post


Link to post
Share on other sites

This topic is 2833 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this