views:

131

answers:

5

I have this question in mind: I need to make a scene that looks like a real sky. My first idea was to make a cube and texturize it. It wasn't that good looking. I came up with the idea of using a sphere. But I couldn't light it from inside. I've put the camera on the origin watching (0,0,-100). Ambient and specular light source also at the origin. Couldn't see any thing lit! What are the ways of making a sky and how can I light the inside of a sphere?

+2  A: 

Try changing the cull mode since you're on the inside of the sphere.

I'm an XNA guy, but it appears that this would be the OpenGL equivalent. If you have ambient lighting on as you said, you should be able to see something regardless of normals, I believe.

bporter
+1  A: 

Try flipping the normals of the sphere (more search results here). In general rendering engines use algorithms to determine what could not be possibly seen and thus should not be rendered; one such technique is backface culling. I'm guessing that the sphere is created in the typical way where the normals project out of the sphere, away from the center; you need your normals facing the opposite way.

I82Much
I use glutSolidSphere. Normals are right and changing the normals are tricky and buggy for it has some unexpected results!
pooya
+1  A: 

If it's lit from outside, but dark from the inside, then it's probably that the normals of the sphere are pointing in the wrong direction.

Assuming that you're doing phong/gouraud lighting, the cosine between the normal and the view direction will be computed somewhere. The cosine will be negative and your graphics card will clamp to zero which results in black color.

So, if your normals are specified explicitly, you should try inverting their direction -> multiply with -1. If you have just vertices and faces, you might want to change the vertex order in the faces. Just switch two indices. (1-2-3) -> (1-3-2). This changes the order from clockwise to counterclockwise (or reverse). To test your results, you can switch backface culling on and off and see what happens.

A: 

Problem solved. Thanks but normals are not the answer. I use glutSolidSphere so normals are not wrong. try using glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); that should do the job for ya.

pooya
Actually, that is the same thing. You just ignore that the normals are pointing in the opposite direction.
You should accept bporter's answer since you did what he suggested, or I82Much's, since this is quite equivalent
Calvin1602
thanks for your mention!
pooya
A: 

When I make a sky dome, sky box, or sky plane, I don't actually light it. I just put a texture on it and render it.

glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
Render sky dome
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);

However, the problem with this is that changing state can be expensive. So one way to eliminate the GL_CULL_FACE state change is to make sure your normals are pointing the right way. If CULL_FACE is set to CCW (Counter ClockWise) then the normals should be pointing toward you. However, if CULL_FACE is set to CW (ClockWise) then the normals should be pointing away from you. The only way I can see to eliminate the GL_LIGHTING state change is to use shaders and define your own lighting scheme. However, I don't know if that is more or less expensive.

The sky box issue is a similar story but it has other problems. You can run into distortion issues if your viewpoint is not at the center. What I generally do is render the sky box first, centered on the camera, then clear the depth buffer and render everything else. That way your sky box doesn't have to be ridiculously big.

Ned