Planet
glint · Examples · Tutorials · Gallery
A turning planet drawn in 2D: the point on the sphere under each pixel, 3D noise for continents and clouds, ice at the poles, city lights on the night side and a thin atmosphere.

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.
The code
One pass, in GLSL.
fragment shader
#version 300 es
precision highp float;
uniform float time;
uniform vec2 resolution;
in vec2 v_texcoord;
out vec4 fragColor;
float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec2 hash2(float n) { return fract(sin(vec2(n * 127.1, n * 269.5)) * 43758.5453); }
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }
vec3 pal(float t) { return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))); }
float hash3(vec3 p) { return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453); }
float noise3(vec3 p) {
vec3 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(mix(hash3(i), hash3(i + vec3(1, 0, 0)), f.x), mix(hash3(i + vec3(0, 1, 0)), hash3(i + vec3(1, 1, 0)), f.x), f.y),
mix(mix(hash3(i + vec3(0, 0, 1)), hash3(i + vec3(1, 0, 1)), f.x), mix(hash3(i + vec3(0, 1, 1)), hash3(i + vec3(1, 1, 1)), f.x), f.y), f.z);
}
float fbm3(vec3 p) { float v = 0.0, a = 0.5; for (int i = 0; i < 6; i++) { v += a * noise3(p); p *= 2.02; a *= 0.5; } return v; }
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
vec2 p = uv / 0.38;
float r2 = dot(p, p);
vec3 L = normalize(vec3(-0.7, 0.3, 0.6));
vec3 col = vec3(step(0.998, hash(floor(gl_FragCoord.xy))) * 0.8); // stars
if (r2 < 1.0) {
vec3 n = vec3(p, sqrt(1.0 - r2)); // the point on the sphere
vec3 s = n;
s.xz = rot(time * 0.1) * s.xz; // turn it
float h = fbm3(s * 2.0);
float land = smoothstep(0.5, 0.52, h);
vec3 surf = mix(vec3(0.02, 0.1, 0.3), mix(vec3(0.15, 0.4, 0.1), vec3(0.5, 0.4, 0.25), smoothstep(0.55, 0.7, h)), land);
surf = mix(surf, vec3(0.9), smoothstep(0.75, 0.85, abs(s.y) + h * 0.2)); // ice caps
vec3 cs = s;
cs.xz = rot(time * 0.03) * cs.xz;
float cloud = smoothstep(0.5, 0.75, fbm3(cs * 3.0 + vec3(0.0, 0.0, time * 0.02)));
float day = max(dot(n, L), 0.0);
col = mix(surf, vec3(1.0), cloud) * day;
col += vec3(1.0, 0.7, 0.3) * land * step(0.8, noise3(s * 60.0)) * smoothstep(0.1, -0.1, dot(n, L)) * (1.0 - cloud); // cities
col += vec3(0.3, 0.5, 1.0) * pow(1.0 - n.z, 3.0) * (0.2 + day); // atmosphere at the rim
}
float edge = sqrt(r2) - 1.0;
col += vec3(0.3, 0.5, 1.0) * exp(-max(edge, 0.0) * 25.0) * step(0.0, edge) * 0.5 * max(dot(normalize(vec3(p, 0.0)), L) + 0.5, 0.0);
fragColor = vec4(pow(col, vec3(0.4545)), 1.0);
}More More GLSL examples
Sierpinski tetrahedron · CRT television · Lightning · Candle · Isometric city · Gyroscope · Moiré · Toon shading