PDA

View Full Version : The negative side of the Z axis appears darker



Voyez
02-15-2010, 02:55 AM
Hi,

Well, that's the problem...:
No matter how I configure the lights and all the other parameters, that I get half of the world without diffuse light.

Anyway, more exactly:
I have a world with only a floor ( just a plane made of some hundreds of triangles ) and a Skybox, both with modelated textures, normals and the materials (ambient, diffuse, specular) set to { 1.0f, 1.0f, 1.0f, 1.0f }.
I import them from a .obj and then I calculate the normals, so I now they exist, and they are normalized, but i have no idea about the facing of the polygons. However, I have set everything posible to GL_FRONT_AND_BACK, and I called


glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

during init, so it may not be a problem.

And then it comes:
No matter if it's a fixed or viewpoint light, with wide or narrow cutoff, the color...
If it is a directional light, nothing gets hit by its diffuse component.
And if it's positional, only a half of the world gets illuminated by the diffuse light.
The strange thing is that it depends on the position of the camera, and that the floor and the skybox do the exactly the opposite, but allways along the X axis.
So, if I set a pure diffuse light, from where I am I see only the Z positive side of the Sky box and the Z negative part of the floor.

Any idea?
I do not post the code cause I think there's not much more from what I told, but if you think it's necessary, ask for it.

Pziko
02-15-2010, 08:44 AM
As an experiment, what happens if you glEnable(GL_CULL_FACE)?

I think I'd double check my normal calculations.

strattonbrazil
02-15-2010, 09:14 AM
Just some tips:

As Pziko suggests, try glEnable(GL_CULL_FACE) just to know what is facing you and what isn't.

Without lighting, render your geometry using the normal as the color and make sure you get what you're expecting.

Are you using texturing? I assume not since you don't mention it.

Are you using glColorMaterial?

Are you specifying glLight at the correct location relative to your projection and modelview matrices?

Voyez
02-15-2010, 10:26 AM
Well, still nothing...

About facing:

As Pziko suggests, try glEnable(GL_CULL_FACE) just to know what is facing you and what isn't.
I tried it. Then I see only the floor, so I suppose that skybox is pinting the wrong way.
A part from that, it still happens the same on the floor triangles.

about the other things:

Without lighting, render your geometry using the normal as the color and make sure you get what you're expecting.

If you meant to render without lights to see if it is what it is supposed to be...yes, it is.


Are you using texturing? I assume not since you don't mention it.
Are you using glColorMaterial?

Well, i just insinuated it.
I'm using RGBA bitmaps as 2D textures, with GL_MODULATE, over white material.
It really doesn't matter if set the material using Colormaterial or setting Ambient, Diffuse, Specular and shininess independently. I get exactly the same.

About the last suggestion, I have tried different light positions, and I get what I expected but the Diffuse light works only on the half axis I told before.

I really don't understant it...I started thinking that maybe my computer became self-conscious and it's learning what jokes are...hehe.

Here you can see what happens:
Ambient light is set to { 1.0f, 0.0f, 0.0f, 0.0f }
Diffuse light is set to { 0.0f, 1.0f, 1.0f, 1.0f }
http://f.imagehost.org/t/0185/Lights.jpg (http://f.imagehost.org/view/0185/Lights)
http://i.imagehost.org/t/0216/Lights2.jpg (http://i.imagehost.org/view/0216/Lights2)

Note: The cross line between colors corresponds to the X axis of my position in World coordinates, being the redfloor side the Z negative.

You can see that only a half of the floor is "Diffuse Illuminated", and that it happens the opposite with the skybox.

Having noticed that the skybox has the normals facing the wrong direction may give an idea of why it does the opposite, but I still don't know how shoud I manage to get the other half world illuminated.

strattonbrazil
02-16-2010, 09:24 AM
If you meant to render without lights to see if it is what it is supposed to be...yes, it is.

No, I don't mean just turn off the lights. I mean use your normals as the colors with the lights off. Without texturing and lighting, you can make sure your normals are correct by using them as the color. For example, if you have a plane and use the normals as the color, you should probably have the same color across the plane. If you get wonky colors or it goes black just by moving across the axis, then you know your normals are messed up.

strattonbrazil
02-16-2010, 09:28 AM
By the way, can you post your matrix code? Make sure you're calling glLight in the correct location. When you set the light's position, it needs to be after any camera moves. For example, if you are using gluLookAt, you need to set your light position in world space after then call or in camera/eye space before the call to gluLookAt, since OpenGL will multiply the camera position you specify by the modelview matrix and do all of it's fixed functionality lighting in eye space.