Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Brett Crain

OpenGL - Sky/Sun

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

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!