Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Planetary rings / asteroids

Planetary rings / asteroids

Ysaneya
Journal of Ysaneya · · 3 min read
1,990 6
Planetary engine

The interfaces and rewritting of shaders in GLSL is progressing quite well, I'm pretty much ready to jump on the re-implementation of texturing, and improving water.

I got ride of the seams in some detail textures that were caused by multiplying the texture coordinates by a scale constant in the shaders ( in order to tile the texture a lot of times on the terrain ). It's a bit tricky to explain, but it was easy to implement, so I'll come back on the technique later ( if I don't forget ).

Rings / asteroid fields

I spent most of my week end refining the rendering and tweaking the asteroid fields.

Ring lighting

I introduced lighting of the rings ( yeah, it was missing in the previous update ). My natural approach was to compute a standard diffuse lighting term ( N^L with N being the ring normal, and L the sun direction ) and to add a bit of ambient on the unlit side of the ring, but to my surprise it didn't seem to work that way in reality. Apparently, the rings can range from very dark to very lit when seen from their unlit side, depending on the thickness of the ring. So instead, my lighting uses this formula:

float color = pow(gl_Color.x, 1.0 + (1.0 - diffuse.w) * 3.0);


With gl_Color.x being the vertex-to-sun angle ( ranging from 0.0, for unlit angle, to 1.0 for totally lit angle ), and diffuse.w being the opacity, taken from the ring texture.

Another aspect of ring lighting is that I didn't want to render the ring geometry twice with backface culling, but only once without backface culling; so depending on where the camera is, relative to the ring plane, the coefficient for lighting is adjusted ( typically, coef = +- N^L, with +- being the sign of the distance from the camera to the plane ).



Ring texturing

I was previously using a static texture ( Saturn's, to be more precise ). The ring texture is now procedurally generated. Nothing very advanced technically: a set of 3 main colors are chosen, and given some probabilities. Then, bands of colors are added together in the ring texture ( for the opacity in the alpha channel, they can be removed too ). The algorithm is running in 3 passes where the width of those bands of colors are varying.



Dust lighting

The dust particles are now looking up the correct color in the ring texture, so the texture and the dust particles all match together. I've also introduced alpha-blending for them, which makes them look much nicer than raw points. They are also fading in/out with distance instead of popping up suddenly.



Shadowing

Remember, the planet is still missing in the screenshots ( I can't add it before fixing some issues with the cascading Z frustums, to allow for correct Z-Buffer sorting ).

The shadowing of the planet is computed in the pixel shader by finding the distance between the pixel and the line passing through the planet center, with the sun direction. If this distance is lower than the planet radius, the pixel is in shadow.

The penumbra is also calculated ( at the moment with a constant, but later, will match the average thickness of the atmosphere ).



Precision issues

Last but not least, I had to fix many precision issues ( 64-bits coordinates are required to place objects at tens of AUs from the scene origin ), and render some effects such as the dust in camera space.

Besides impostors and minor bug fixes, I'm pretty much done with rings and asteroids fields.

Discussion

Loading comments...