Coding 'till the morning light

On an alien world, a spaceport is built on a desert area bordering a mountain edge. The port is used to transport resources to space and allow workers to travel back and forth between the mine colonies and their homeworlds. The stone-cold desert ground consists of a hard, sandy floor. At night, the thin atmosphere freezes over and forms an ice layer on the sand.

This is a shader effect I made as part of a multitexture shader for the terrain. The shader takes 6 textures: ground (the sand), ground overlay (the ice) and ground mask (for blending ice on sand). Same for the walls. What happens is when the time value (0.0 to 1.0) hits night (1.0), the ice is completely covering the sand. During day (0.0), the ice is not visible at all. A straight blending would result into a fading transition between sand and ice, which is rather boring. Inspired by this tutorial on melting snow, I decided to spice it up.

The code for melting is really simple and requires only two lines. First, we need to determine whether or not to melt at all based on the time value. Then, we blend the ice with the ground by the mask value (as we would using normal multitexturing):

You can now use groundColor to draw with gl_FragColor, or apply it with further multitexture mixing (e.g. by determining whether you're drawing on a wall or a flat surface). The edge of the ice in the example is rather hard. If you want to apply smoothing, you can use smoothstep to do that. The code will be:

With some creativity, you can create many different environments that look alive and in motion: growing vegetation, filling water channels, solidifying lava streams, glowing runes appearing on the floor, your imagination is the limit ;).