Planetary Body Shader Part 2

By
Dave
Project
Published
9 Feb 2010 19:30
Last Modified
13 Jan 2013 17:56

In Part 1 I showed some screenshots of a planet rendered using multiple effects. I'll discuss each of these in turn, and begin with a composite image to show how each effect contributes to the overall image.

Earth Shader Composite

Figure 1. Composite image showing per-pixel, single-direction lighting (top left), addition of bump-mapping and specular (Phong) reflection (top right), addition of atmospheric scattering (bottom left), and addition of clouds and cloud shadows (bottom right).

The first thing I needed to do was create a model. I could have used a predefined sphere, but chose instead to generate the mesh algorithmically so that I could easily control the number of vertices.

Texture

Once I had a model, the first thing I needed to do was to apply a texture. NASA has an extensive image library, and the Visible Earth site has a collection of land maps for Earth. These maps are Equidistant Cylindrical projections, so my texture coordinates were simply:

x = λ
y = θ

where

λ = longitude,
θ = latitude

Lighting

The Shader Series on the XNA Creators Club site is a great introduction to lighting. My initial lighting model was a simple per-pixel shader, with a single directional light source from the sun. I subsequently added specular reflection using a Phong shading algorithm.

Relief

In order to show surface features without significantly increasing the number of vertices in the planet model, bump (normal) mapping can be used. There are numerous sources of normal maps on the Internet, available in various formats (I'm using DDS), and a good sample of how to implement normal mapping in a shader can be found on the XNA Creators Club site.

Atmospheres

There are many discussions on the subject of atmospheric scattering, many of which reference the work by Nishita et al. The article "Accurate Atmospheric Scattering", GPU Gems 2, Chapter 16 by Sean O'Neil served as a good starting point and is available here.

Clouds

The Visible Earth site also has a collection of cloud maps. This texture is then rendered on another sphere model above the surface of the planet.

Shadows

It was an important effect to cast shadows from the clouds onto the surface, particularly toward the terminator where the shadows are longer and not directly below the clouds themselves. My first approach was to implement a sphere-ray intersection algorithm in a pixel shader to dertermine the surface position of a shadow cast from my cloud sphere, and subtract the result from the existing surface texture.

Comments

By
Daniel
9 Feb 2010 19:58
Awesome work ! Can't wait to see it in action ! (video screencast ?)
Cheers, Dan
By
Isak
17 Mar 2010 15:23
Hi, I have a few questions, the sphere you make, do you calculate the tangent when you model it or in the shader? I was also wondering how these effects are added to each other. Is it a single shader that does everything or how does this work?
By
Dave
21 Mar 2010 00:53
The ground, clouds, and atmosphere are each seperate effects which are additively blended.
By
Louis Deane
2 Apr 2010 14:52
Hi, just a quick question from me. Are you doing anything to compensate for the distortion that will happen at extreme latitudes due to the conversion from polar coordinates?
cheers
By
Dave
2 Apr 2010 16:12
Hi Louis, great question. At the moment there is no compensation taking place so there will be some distortion. My current thinking is either to a) not worry about it, or b) switch to a projection that doesn't suffer from distortion, such as TOAST (Tessellated Octahedral Adaptive Subdivision Transform). Being realistic, there are a lot of items on my TODO list, so I suspect the answer will be a) for some time! Regards, Dave
By
Isak
1 Jun 2010 15:23
Hi again, so just to be clear. You basically draw 3 spheres, first one the earth bumpmapped, then the earth shading and last the earth atmosphere and blend all these together, 3 shaders in total?
By
Dave
1 Jun 2010 15:48
Actually there are currently 4 shaders and 4 spheres:
1) A bump-mapped ground texture, which also renders cloud shadows.
2) An atmospheric effect applied at the ground level with the same size sphere as 1).
3) An atmospheric effect applied to the sky with a larger sphere than 2).
4) A cloud texture with a sphere of size between 1) and 3).

In the future I may look to rationalise these for performance purposes, however in the meantime it is helpful to have them as seperate components.
By
Caseysoics
29 Aug 2017 04:23
<a href=https://www.viagrapascherfr.com/>Click here>>></a>

Add Comment

*
*
*
Captcha
*
*Required