Archived

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

How to render atmosphere? (screenshot)

This topic is 5040 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''ve managed to get my billboards working, to show stars and my skybox looks ok (showing nebula), just wondering how on earth I render an "atmosphere" around the edge of a planet (sphere). As you can see from the screenshot, I''ve tried billboarding a "ring" texture, but I can''t seem to get the radius or position correct so it fits! (picture top of page) http://www.robinmj.0catch.com Anyone done anything like this before? Cheers.

Share this post


Link to post
Share on other sites
That looks pretty impressive as is, but anyways, for the atmosphere effect you COULD use pixel shaders to create volume fog, that should create the right effect, search msdn and nvidia''s site you should find plenty of crap on volume fog (its also in the dx sdk )

Share this post


Link to post
Share on other sites

Well thats my intention for when the player goes into an atmosphere (in a gas giant for example), but in this case, what I want is haze around the silhouette of the planet - for when the eyepoint is at a distance much greater than the atmosphere.

Share this post


Link to post
Share on other sites
I think,you need to use correct size/distance for billboard,not equal to radius/distance of center of sphere.
Just draw on paper camera close to planet,planet,and billboard.
You will see that planet are seen with bigger angle than billboard.


Also,you coult try,after rendering of planet surface,use relatively simple pixelshader on all screen(and do that only if planet are close,of course). Say,shader could pick color from special texture at

x=dotproduct(NormalizedRay,V)
y=abs(crossproduct(NormalizedRay,V) )

where
l= | VectorToPlanet | ;
V=VectorToPlanet ;
and texture corners at
-MaxPlanetDist,0
,MaxPlanetDist,MaxPlanetDist;
if you want you could use V=|VectorToPlanet|*SomeFunction(l);


Texture pixel with polar coordinates (alpha,r) stores color of atmosphere at [angle between planet and ray]=alpha ,[distance to planet] = r; and alpha value that are then used to blend it with billboard(so pixelshader will be smoothly replaced withbillboard).Alpha should smoothly vary from 1 to 0 as r varies from 0 to MaxPlanetDist.

That texture should contain pre-calculated atmosphere to planet 'raytracing' results.Result are as accurate as raytraced volumetric atmosphere!

Let c=(color from texture) and bc=(color from billboard);

pc.rgb=(c.rgb*c.alpha+bc.rgb*bc.alpha)/(c.alpha+bc.alpha) .
pc.alpha=c.alpha+bc.alpha
blend pc to screen.

Inform me if you will use that

Regards,

Dmytry Lavrov.


...

[edited by - Dmytry on February 23, 2004 1:44:09 AM]

Share this post


Link to post
Share on other sites
Woah, that does look very nice! Let us know how if you work out a solution (it does look like the radius/size of the billboard is incorrect).

Is that ring just a texture which is mostly transparent, but has a ring around the edge? And do you just draw it at the centre of the planet with a size such that the edge of the texture is outside the planet?

sam

Share this post


Link to post
Share on other sites

The ring is a billboard texture, centered at the planet. I think I''ll never get it to fit properly, even when I calculate the horizon point and place it there it doesn''t fit!

What I''m going to do is use ring geometry - rotate it billboard style and fit it around the horizon. Will get back to you all on whether it works or not!

Share this post


Link to post
Share on other sites
You just have to intersect a sphere with a plane, centered at the planet''s origin, with the normal pointing in the direction of the camera. This intersection gives you a set of line segments in 3D, which you can then scale to the planet''s radius. This gives you a first set of vertices. Set alpha to 1 for these vertices. Now do the same, but with a bigger scale, and set these vertices to alpha 0. Use a nice gradiant texture, and voila.

Y.

Share this post


Link to post
Share on other sites
quote:
Original post by Ysaneya
You just have to intersect a sphere with a plane, centered at the planet''s origin, with the normal pointing in the direction of the camera. This intersection gives you a set of line segments in 3D, which you can then scale to the planet''s radius. This gives you a first set of vertices. Set alpha to 1 for these vertices. Now do the same, but with a bigger scale, and set these vertices to alpha 0. Use a nice gradiant texture, and voila.

Y.



Isn''t that the same as kind-of drawing a circle on a plane? ie. a normal circle transformed to the orientation of the plane? Also, I need to place the object around the horizon, rather than the centroid of the sphere. I thought about pre-generated geometry (just a ring) that I scale to the horizon and rotate by the inverse of the camera view matrix. Err, thats probably wrong (geometry isn''t my strong point), but I''ll give it a go.

Share this post


Link to post
Share on other sites
quote:

Isn''t that the same as kind-of drawing a circle on a plane?



Yes, that''s what the intersection of a sphere and a plane is

quote:

I need to place the object around the horizon, rather than the centroid of the sphere.



That''s why i said you should scale your sphere to the planet''s radius.

The "ring" is formed of two circular pieces; the inner one is the circle with the planet''s radius; the outter one, the radius of the planet plus the atmosphere thickness.. this will give you a ring in 3D that is always oriented towards the camera (like a billboard).

Y.

Share this post


Link to post
Share on other sites
I kind of understand what you mean, but I don''t think I can afford to do a per-frame sphere/plane intersection clip! At least, I''ll pre-do the intersection by generating the ring. Now we are both talking the same language. The only thing that is different is that the ring cannot be centered at origin of the sphere, or just be scaled to its radius, because the horizon is usually closer to the eyepoint than the center, if you see what I mean. This is what is complicating matters somewhat

Share this post


Link to post
Share on other sites
quote:

I don''t think I can afford to do a per-frame sphere/plane intersection clip!



And why ? Are you running on an old 286 SX ? Any pentium with more than 100 Mhz should be able to make these calculations at more than a few hundred thousand times per frame... and you only need to do it once per frame. Premature optimization is the root of all evil, remember ? And i''d rather get it to work first, before caring about "how fast" it runs..

quote:

the horizon is usually closer to the eyepoint than the center, if you see what I mean.



Sorry but... no. How do you define the "horizon" ?

Y.

Share this post


Link to post
Share on other sites
quote:
Original post by Ysaneya
quote:

I don't think I can afford to do a per-frame sphere/plane intersection clip!



And why ? Are you running on an old 286 SX ? Any pentium with more than 100 Mhz should be able to make these calculations at more than a few hundred thousand times per frame... and you only need to do it once per frame. Premature optimization is the root of all evil, remember ? And i'd rather get it to work first, before caring about "how fast" it runs..

quote:

the horizon is usually closer to the eyepoint than the center, if you see what I mean.



Sorry but... no. How do you define the "horizon" ?

Y.




Well if you draw a line from the eye point to the edge of the sphere, like this:

......................+
....................+p***
..................+ *******
............eye+ *********
..................***********
...................*********
....................*******
......................***

Apologies for my ridiculous ascii art! But the intersection of the ray from the eye point to the horizon of the sphere does not intersect at at the plane of the sphere (sometimes it does of course), it intersects at point "p". Or have I totally misunderstood the whole problem (more than likely!)?

As for making the calculation of the sphere/plane intersection, thats not a problem, I thought you meant cutting the mesh against the plane, which is totally out of the question.


[edited by - Robbo on February 23, 2004 4:29:53 PM]

Share this post


Link to post
Share on other sites
What you need to do is create a (truncated) cone shape... The point of the cone is at the center of the planet, and the base is towards the camera and some distance above the surface. The cone can be truncated at the horizon level for easier texturing. The opening angle of the cone (how "pointed" it is) depends on the location of the camera.

Example on paper: Draw a circle, then place a point some distance outside of it that represents the observer. Use a ruler to draw a line from the observer to the center of the circle, and another that just touches the edge of the circle at a single point. This point will be the horizon. Draw a line from that point to the center of the circle (perpendicular to the 2nd line).

Now you have a triangle whose angles can be calculated from the known variables... The angle of the point at the center of the circle is half the cone''s opening angle. It''s a good idea to limit how "tight" the cone can get (e.g. set a minimum of 20 degrees or so) in case you can get close to the surface.

(I''d have pictures but we just did a spring cleaning at the web server...)

Share this post


Link to post
Share on other sites
quote:
Original post by Fingers_
What you need to do is create a (truncated) cone shape... The point of the cone is at the center of the planet, and the base is towards the camera and some distance above the surface. The cone can be truncated at the horizon level for easier texturing. The opening angle of the cone (how "pointed" it is) depends on the location of the camera.

(I''d have pictures but we just did a spring cleaning at the web server...)



Ahhhh! Got it, thanks. Intelligence bypass earlier. Obviously not drunk enough coffee this evening!

Share this post


Link to post
Share on other sites
Here''s some maths to help you with your problem:

R: radius of planet
D: distance from camera to planet''s center
x: distance toward camera that ''ring'' must be brought to fit
y: inner radius of ''ring'' to fit planet
pi: 3.1415926....

x = R*cos(pi-sin-1(R/D))
y = R*sin(pi-sin-1(R/D))

This will put the atmospheric ring at the correct position to just encompass the visible horizon of the planet from the perspective of the camera.

Unfortunately I did not have the pleasure of seeing your picture, since your download limit has been reached on that account. Perhaps you could email it to me when its fixed (through my profile)?

Cheers,

Timkin

Share this post


Link to post
Share on other sites
quote:

> R: radius of planet
> D: distance from camera to planet's center
> x: distance toward camera that 'ring' must be brought to fit
> y: inner radius of 'ring' to fit planet
> pi: 3.1415926....

> x = R*cos(pi-sin-1(R/D))
> y = R*sin(pi-sin-1(R/D))


Note that
cos(pi-a) = cos(pi+a) = -cos(a)
sin(pi-a) = sin(a)
so it's anyway very wrong

My 5 cents: use

x = D*(1-(R/D)^2)
y = R*sqrt(1-(R/D)^2) (*)



Reminds special relativity?
Both are derived from Pifagor theorem
why that formules:
let L=distance of horison point;
L^2+R^2 = D^2;
L=sqrt(D^2-R^2);

R/Y = D/L
y = L*R/D =R*sqrt(D^2-R^2)/D;

L/x = D/L
x= L^2/D = D - R^2/D

p.s.
and from there you can find that it's the same as
x = D-R*sin(asin(R/D))
y = R*cos(asin(R/D))
because
cos(asin(a))=sqrt(1-(a)^2)
and
x = D*(1-(R/D)^2) = D-R^2/D = D-R*sin(asin(R/D))
[edited,typo -sin repaired]
p.p.s.
^2 stands for 2


...

[edited by - Dmytry on February 24, 2004 5:04:02 PM]

Share this post


Link to post
Share on other sites
Another way to do this would be by using silhouette fins. Find the silhouette edges with respect to the camera''s point of view and extrude the vertices to create the fins. Texture it with your atmospheric glow texture.

Share this post


Link to post
Share on other sites
I''m not sure how much use it would be, but you might find Planet Engine interesting. Unfortunately, the source code isn''t provided, but you might be able to get some inspiration from the demo, or work out how it does its stuff by careful inspection.
Even if it isn''t much help on its own, you might find something useful in the links section of that site.

John B

Share this post


Link to post
Share on other sites
quote:
Original post by JohnBSmall
I'm not sure how much use it would be, but you might find Planet Engine interesting. Unfortunately, the source code isn't provided, but you might be able to get some inspiration from the demo, or work out how it does its stuff by careful inspection.
Even if it isn't much help on its own, you might find something useful in the links section of that site.

John B


Yea, I've been there a million times! It looks fantastic, but the lack of source is a real pain in the buttie! Its like showing me the sweets but not letting me taste one.

Anyway, I'm about 50% graphics artist and 50% programmer, so I find both difficult but need both 100% to make the software I want to make! I wish I'd paid more attention in math class


[edited by - Robbo on February 24, 2004 7:23:27 PM]

Share this post


Link to post
Share on other sites