Proper Lighting of a Sphere

Started by
9 comments, last by Conqueran 18 years, 4 months ago
I'm trying to properly light a sphere made up of several polygons.. I set the normals of all polygons and yet I get this wierd effect. I can see the inside of my sphere! parts of it light up correctly, but I see the inside of it at parts and its black.. I'd post a picture but I don't know how to post pictures on the forums... Has anyone experienced this before? If so, what is happening? I know my normals are set correctly and I used glEnable(GL_NORMALIZE) to make sure they are unit vectors, so what can be going wrong?
Advertisement
Sounds like you are reversing the winding on some parts. That's easily done if you calculate the vertices for just part of the sphere then use reflections to find the rest of the vertices. If you're using back face culling try turning it off and it will be easier to tell what is happening. Just drawing a hemisphere will also make it easier to figure out what is going wrong as well.
Keys to success: Ability, ambition and opportunity.
Sounds like you are reversing the winding on some parts. That's easily done if you calculate the vertices for just part of the sphere then use reflections to find the rest of the vertices. If you're using back face culling try turning it off and it will be easier to tell what is happening. Just drawing a hemisphere will also make it easier to figure out what is going wrong as well.

try inverting your normals. glNormalize doesn't gurantee correctness. also if you're using a negative scale, you're actually flipping it inside out, which would still make it look like a sphere but with the normals inverted.

Tim
It could also be a depth-buffer problem. Are you culling back faces?
I tried inverting the normal.. The sphere points are held in a data file, I simply draw the polygons from the data file and calculate the normals for each.. I tried normalizing the vectors myself, I get the same result.

A depth buffer problem? I'm not sure what u mean by culling back surfaces..

Brian
Quote:Original post by Conqueran
I tried inverting the normal.. The sphere points are held in a data file, I simply draw the polygons from the data file and calculate the normals for each.. I tried normalizing the vectors myself, I get the same result.

A depth buffer problem? I'm not sure what u mean by culling back surfaces..


Polygons are considered to be front-facing or back-facing if their vertices appear in counter-clockwise or clockwise order (respectively). You can enable culling so that back-facing polygons aren't drawn. For details, see Chapter 2 of the Red Book. The depth buffer is also explained in that chapter.
Free Mac Mini (I know, I'm a tool)
I assume you are using the vertex normals of the sphere, i.e. direction from the center to the vertex. Try checking those against face normals, i.e. cross product of two consecutive edges of a face. The dot product of the vertex and face normal should be positive. If it's negative your winding is reversed.

It might seem intuitive that the normal should specify the front face, but it doesn't. If the user is suppose to be inside the sphere then the front face is the inside faces, but the normals would still point out.

Easiest is really to just turn off back face culling and set differant colors for the front and back faces. Without a picture the best guess is that front faces are inside faces on some polygons and outside faces on others.

PS: As far as posting pictures you need web space to upload it to. Generally your ISP provides a small amount of space for creating personal web pages. You are basically given a directory to upload files to. They generally provide directions on how to determine the URL for the files you uploaded. Beyond that is hosting. As an example for $5 a month with yahoo you can get 500mb of space for creating your own web page or making files accessible on the web. Even better with GDNet+ you get web space on this site in recognition of your outstanding support of the site :)

PSS: Oh yes, if you're in college then your school most likely provides you web space as well. So if you're in college then this would be a good time to look into how to set and use your web account since you're already paying for it.
Keys to success: Ability, ambition and opportunity.
What kind of file are you loading the mesh from? To echo the other posters, it may be that the triangles are wound inconsistently; I've sometimes found this to be the case when loading meshes made with certain modeling programs.
hey I culled the back faces and it came out correctly... Thanks :)... I still need to learn a bit apparently ... THANK U SO MUCH... damn I'm happy it works/.
That seems odd. Sounds like you don't have a depth buffer. I've had it fail to give me a depth buffer when I asked for a higher bit depth than available. If you requested a depth buffer then try calling glGetIntegerv with GL_DEPTH_BITS to verify that you actually got a depth buffer. If you got a depth buffer make sure you didn't use too small a zNear, i.e. under 0.1.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement