Problem with light

Started by
4 comments, last by zultan 14 years, 1 month ago
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>
Advertisement
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.
Thx for the answer, but that does not help =/
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
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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Thank you! Now i get it =)

This topic is closed to new replies.

Advertisement