Planetary Rings in Space Nerds In Space

Planetary Rings in Space Nerds In Space

Ring Geometry

Triangles arranged in an annulus

Ring Geometry 2

Triangles arranged in an annulus

Initial u-v Mapping

For each vertex of each triangle:

v is set to 0.0

if the vertex is on the outside edge of the ring, u is set to 1.0;

if the vertex is NOT on the outside edge of the ring, u is set to 0.0;

These values are modified later

Texture:

Texture Features:

* Fades to transparent on left and right edges

* has areas of varying transparency with transparency linked to original pixel brightness

* brighter areas more opaque, darker areas more transparent

Procedurally Customizing Rings

* For each ring, inner and outer radii are chosen

* Range is between 1.0 and 3.0 * planet radius

* Minimum difference between inner and outer radii

* These values do not affect the ring geometary, they are instead used to modify the u-v mapping.

* For texture mapping, v is chosen to be a constant (to replace the 0.0) between 0 and 256, essentially choosing a row of pixels from the texture.

Ring Vertex Shader

* uniform texture 'v' replacement value passed in (uniform for our purposes here means the value is constant for the entire ring). This is what chooses the row of pixels from the texture that we will use.

* Texture coordinate passed in (the u,v mapping coords for the vertex).

* Y coordinate of texture is modified to have the value of uniform v value passed in. (Will be passed on to fragment shader so modified).

Ring Fragment Shader

* uniform (constant) inner and outer ring radii are passed in

* Texture coordinate (with y coord modified already) passed in

* Texture x coordinate is modified to account for inner and outer ring radius.

Ring Fragment Shader: Calculating texture x coordinate

* x coordinate will be come into the shader with a value between 0.0 and 1.0

* Will be 0.0 at the inner edge of the ring geometry

* Will be 1.0 at the outer edge of the ring geometry

* Recall that ring geometry does not match inner and outer ring radii

Ring Fragment Shader: Calculating texture x coordinate

Ring Fragment Shader: Calculating texture x coordinate

newx = max(0.0, (outer_r * x - inner_r + 1.0) / (outer_r - inner_r))

(This made sense to me at the time... and seems to work.)

Casting Shadow of Planet Onto Ring (vertex shader)

* Light position passed in as uniform to vertex shader

* uniform v texture coord passed into vertex shader

* Varying Light direction and position are calculated in vertex shader

Casting Shadow of Planet Onto Ring (fragment shader)

* uniform planet sphere passed in as vec4 (x,y,z and w = radius.)

* uniform inner and outer radius of ring passed in .

Casting Shadow of Planet Onto Ring (fragment shader)

* Ray is cast from each fragment towards light testing for intersection with planet. If it intersects, ring is shaded.

Casting Shadow of Ring Onto Planet (vertex shader)

Using a cubemap for the planet texture

Nothing special in vertex shader for shadows

Casting Shadow of Ring Onto Planet (fragment shader)

* light position passed in as a uniform

* Ring center, normal vector, radius (inside and outside) and texture v passed in as uniforms

* Ray cast from fragment to light and intersection (if any) with ring is calculated.

* Distance of interesection from center is scaled and offset to compute ring texture coordinate.

* Alpha value of ring texture element is used to shade fragment color.