-
Notifications
You must be signed in to change notification settings - Fork 1
Planet Terrain Algorithm (GLSL Shader)
Rufus Pearce edited this page Dec 23, 2025
·
2 revisions
The planet shape is a standard sphere (or cube) where every vertex is pushed outwards based on a math formula (simplex Noise and Fractal Brownian Motion (FBM) in the vertexShader.
-
Warping: Distorts the coordinate space so the terrain doesn't look too uniform.
-
FBM (Fractal Noise): Layers multiple "octaves" of noise to create mountains (rough detail).
-
Ridged Noise: Inverts the noise to create sharp peaks (valleys become peaks).
-
Displacement: Pushes the vertex along its normal vector.
// Inside vertexShader
vec3 warpPos = sphereP * 0.5 + seedOffset;
float warp = snoise(warpPos) * warpScale;
// Offset position by warp to create "swirly" terrain
vec3 noisePos = (sphereP + vec3(warp)) * frequency + seedOffset;
// 1. Standard Soft Noise (Hills)
float n = fbm(noisePos, octaves, persistence, 2.0);
// 2. Ridged Noise (Sharp Peaks)
// abs(snoise) creates a "crease", 1.0 - abs turns it into a peak
float r = 1.0 - abs(snoise(noisePos));
r = pow(r, 3.0); // Sharpen the peak
// Mix them based on the "Ridges" slider
float finalNoise = mix(n, r, ridge);
// Apply heightmap texture if imported
float combinedHeight = mix(finalNoise, texHeight * 2.0 - 1.0, texMix);
// Push the vertex outward
vec3 finalPos = basePos + normalize(baseDir) * combinedHeight * heightScale;