Earth/Planet



Author: Julien Lynge

Description
A shader originally designed for the Earth, though it can be used for any planet. This shader is a modification of code produced by the Strumpy Shader Editor. The original tutorial for creating the earth (minus night lights and night-side coloring) can be found at http://forum.unity3d.com/threads/56180-Strumpy-Shader-Editor-4.0a-Massive-Improvements?p=431828&viewfull=1#post431828

The corresponding cloud shader can be found at http://fragileearthstudios.com/2012/07/03/code-snippets-realistic-earth-and-clouds-shader/, along with a complete Unity package with the shaders, textures, and a camera script for reproducing the screenshot at right.

Textures
If you're looking for Earth textures to use with this shader, we used Blue Marble (from NASA) as the Earth texture. You can find black & white topo images (which you can import to Unity as bump maps) and nighttime lights many places; here's an example: http://www.shadedrelief.com/natural3/pages/extra.html

Features
Day and night lighting.

The night side of the earth is ever-so-slightly desaturated (greyed-out) and tinted blue. Both of these effects are very subtle, so feel free to play with these numbers. The corresponding lines are:

c.g -= .01 * s.Alpha; //lower green by .01 on the dark side - desaturate c.r -= .03 * s.Alpha; //lower red by .03 on the dark side - desaturate c.b = saturate(c.b + s.Alpha * .02); //raise blue by .02; saturate clamps the value between 0 and 1

Night lights.

Lights appear on the dark side and fade in during 'dusk'. The code that sets this is

half invdiff = 1 - saturate(16 * diff); //change the '16' to adjust how far dusk should extend)

Lights are tinted slightly yellow. The two lines below apply the rgb of the lights to the world:

c.rg += min(s.Custom, s.Alpha); c.b += 0.75 * min(s.Custom, s.Alpha);

If you want the lights to be white, just get rid of the 'c.b' line and make the other 'c.rgb'. If you want them bright yellow, get rid of the 'c.b' line with no change to the other line.

Bump map

Supports a bump map for mountains and other features. The bump is taken into account with night lights (e.g. cities that are behind mountains 'turn on' earlier than those atop mountains - each changes when it becomes 'dark.'

Atmospheric shading

A slight light scattering due to the atmosphere is created at the edges of the planet. The color and intensity can be set from the inspector.