Sign in to follow this  

Drawing a shroud around a sphere

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

Hello, I'm trying to draw an atmospheric shroud around the spherical earth. The shroud should look correct for any position of the camera. (The camera is of course never inside the earth itself) My original solution was to draw a donut shaped plane that was co-centered with the earth sphere. That didn't work for a fixed size donut "band" -- since the plane needed to face the camera, its distance to the camera changed as the look at point changed. My current thinking is to draw a 2D donut in screen space hugging the edge of the sphere. My brain is tired and I couldn't figure out how to find the currently displayed curvature. Okay I can see how you'd do this when the sphere center is in front of the projection plane. But what if it's behind the plane, and part of the sphere is visible? Thanks for your thoughts.. Kirby

Share this post


Link to post
Share on other sites
You could render the planet first, applying whatever shading or texturing you would normally use on the surface of the planet. Then, reverse the culling direction (i.e. CCW to CW or vice versa), send the geometry of the planet again, and translate the vertex positions out along their normals. Then apply whatever "shroud" material it is that you want to apply, like alpha blended or maybe something with a fresnel term to modify the color.

This will allow your planet to appear fully visible, and the only faces of the second geometry batch that are not occluded by the planet will be rendered (because of simple z-buffer culling).

You can also vary the amount of translation on the second batch of geometry according to clip space metrics to keep a constant screen space, view space, or world space shroud size. You could do something along the lines of projected space planet position z/w ratio in the vertex shader, and multiply this by the vertex normal and add to the vertex position. That would give you control over the size of the offset.

Would this work for your situation?

Share this post


Link to post
Share on other sites
The "skirt" is a fine solution if you only need a glow around the edges (and not in front of the planet). The trick is that it's not a planar disk with a planet-sized hole in it; it must be a cone section placed around the horizon based on the camera's distance from the planet.

Imagine a cone with the tip in the center of the planet, and its base toward the camera. Where this cone intersects the surface is the inner edge of the atmospheric band, and the outer edge is some fixed distance further out. The opening angle (how "pointy" the cone is) depends on the distance of the camera. The closer you get the closer the horizon will be, and the smaller the angle of the cone.

Let's see if I can figure out the exact math, it's really pretty simple. Take R = planet radius, D = camera distance from planet center... The cone must intersect the sphere at the horizon (where a line from the camera to the intersect point is coplanar with the surface at that point). We get a right triangle with a 90 deg angle at the surface, hypotenuse of D, length of the side from center to intersection is R. The angle between the hypotenuse and this side is acos(R/D). This is the half-angle of the cone. If it goes below 10 degrees or so, clamp it to that limit so the horizon won't get too close when you're near the surface.

You use this angle to place a series of points on the spherical surface at distance of R and (R+T) from the center where T is thickness of the atmosphere.

edit: What I did inside the atmosphere is, I added another conical section from the top of the atmospheric band to a point above the camera to act as a "roof". This roof simply faded into black as you approached the edge of the atmosphere from below. This was all done by just changing texture coordinates. One edge of the texture was black (this'd be the edge of the glow when seen from space), the other a bright color for the horizon. When near the surface, I'd use texture coordinates from 0.5 to 0.75 on the "roof", and 0.75 to 1.0 on the "skirt". As the camera altitude increased I gradually changed the coordinates so that the roof was all 0.0 (black/invisible) and the band had a gradient from 0.0 to 1.0 by the time you reached the edge of the atmosphere. Above this altitude the roof wasn't rendered. It worked rather well for such a dirt-cheap approach.

[Edited by - Fingers_ on August 30, 2005 3:43:20 PM]

Share this post


Link to post
Share on other sites
Thanks for all your answers. Both of the suggestions make a lot of sense. I have to put the sky aside for now to work on the website. I'll let you guys know how the it turns out when I get back to doing sky.

[Edited by - goldenpanda on September 5, 2005 4:06:01 PM]

Share this post


Link to post
Share on other sites

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