Sign in to follow this  

Proper Lighting of a Sphere

This topic is 4379 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'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?

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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