OpenGL - Sky/Sun

Started by
6 comments, last by Brett Crain 23 years, 3 months ago
Question: I''m having difficulties with how to go about creating a sun in my 3D environment. The main problem I''m facing is that if the sun is simply a sphere that is x units away, then x must be farther away than the end of the terrain being drawn and closer than the depth that objects stop being drawn. It isn''t quite that easy though, because generally, having x be farther away than the terrain simply causes the sun to be past the depth that OpenGL chooses to draw. This approach seems impractical to me, but I can''t think of how else to do it. If anyone has suggestions or knows of a site that has info on creating sky/sun effects, please let me know.
Advertisement
goto this site http://freespace.virgin.net/hugo.elias/ and goto the models section, then clouds. I saw a sun in the screenshot so that may tell you something. Also maybe you can set the sun some where right infront of the sky box/sphere. I think thats how people do it. I have never tried it myself yet though.

-SirKnight
Hrmm.. why not just move the sun with the player to give the illusion that it is infinately distant from the player, & to make it seem as though it is staying in one place all the time?
wAVaRiaN''s approach sounds good to me as long as the sun stays behind everything.

For example if you set the constant distance to the sun to be 100 units and your map can extend to 150 into the horizon, then there may be cases where the sun is in front of some terrain and thats not quite right...
--------------------------I guess this is where most people put a famous quote..."Everything is funnier with monkey''s" - Unknown
Yes, I currently have the sun drawn in relation to the camera and all is well except for the problem I addressed.

For the sun to be farther than the terrain and closer than the depth cutoff simply doesn''t work (sense the depth cutoff doesn''t stay constant along the screen). If anyone has played games where looking left and right causes certain objects to come into and out of the depth cutoff, that''s what im talking about.

So basically, at the moment, my sun works but dissapears when viewed at certain angles (or half of it is cut off, etc.)

What I would like is to be able to draw a picture of the sky and sun to the "background" (not sure what to call it). And once that is drawn, proceed to drawing the world polygons so that they coverup parts of the sky/sun. This approach would eliminate problems that the depth-cutoff presents...
Yes, I currently have the sun drawn in relation to the camera and all is well except for the problem I addressed.

For the sun to be farther than the terrain and closer than the depth cutoff simply doesn''t work (sense the depth cutoff doesn''t stay constant along the screen). If anyone has played games where looking left and right causes certain objects to come into and out of the depth cutoff, that''s what im talking about.

So basically, at the moment, my sun works but dissapears when viewed at certain angles (or half of it is cut off, etc.)

What I would like is to be able to draw a picture of the sky and sun to the "background" (not sure what to call it). And once that is drawn, proceed to drawing the world polygons so that they coverup parts of the sky/sun. This approach would eliminate problems that the depth-cutoff presents...
If you don't want it affected by any depth testing, just disable depth testing (glDisable(GL_DEPTH_TEST)) before you draw the skybox/sun, then enable it and draw the rest of your scene.

The only problem you may encounter here is that, if your sun is being drawn as a sphere (rather than a billboarded textured quad, as I generally prefer), the lack of depth testing may cause freaky artifacts as back faces of it may get drawn over front faces.

Hope that helped

------------------------------------------------------
"Construct a weapon. Look around you... can you form some sort of
rudimentary lathe?"
- Guy Fleegman, Security Chief, NSEA Protector


Edited by - Bad Monkey on January 14, 2001 11:05:33 PM
Thank you very much for the idea, i knew of disable(DEPTH_TEST)... and now that i think of it, i feel foolish that I didn''t try that earlier.

The sun is all spiffy now... well except for that the backfaces of the sphere are getting draw to it, but that''s just because I''m too lazy to change it to a circle at the moment.

This topic is closed to new replies.

Advertisement