Opus Motion ★ Star on GitHub

3D · terrain-build-3d

Terrain build (3D)

A procedural mountain heightmap rebuilds itself in labelled stages — flat, noise, fractal, erosion, materials, sun, atmosphere, clouds, lens — with a typing code panel, then a cinematic eased fly-by past the peak.

A free, MIT-licensed 3D motion graphic from the Opus Motion Library — 616 motions for Remotion, React and plain HTML.

Terrain build (3D): three frames of the 3D motion graphic, start, middle and end
Terrain build (3D) — start, middle and end of the 21.7-second motion.

What Terrain build (3D) is for

"How it is made" / generative-art explainers: show a world being built step by step, then reward with a hero fly-through.

  • 3d
  • terrain
  • procedural
  • code
  • flyby
  • three
  • contours
  • topographic
  • iso-lines
  • dive
  • loss landscape
  • gradient descent
  • optimisation
  • ml explainer

Details

Category
3D motion graphics (three.js)
Length
21.7 s (650 frames at 30 fps)
Formats
16:9, 1:1, 9:16
Weight
heavy (three.js / WebGL — export to video for mobile)
Transparent overlay
no
Seamless loop
no
Text props
stages
Colour props
contourColor trailColor
Mood
mid, 3d, cinematic, nature
Roles
subject
Pairs with
End card credits, Typewriter code window, Film finishing stack

Use Terrain build (3D) in Remotion, React or HTML

Remotion project

terminal
# copy this motion into your Remotion project
node cli/mgl.mjs add terrain-build-3d --to ../my-app/src

# render an mp4 (run in the library folder)
node cli/mgl.mjs render terrain-build-3d --props '{"stages":[{"title":"NOTHING","subtitle":"a flat plane.","file":"world.glsl","code":"float terrain(vec2 p) {\n  return 0.0;\n}"},{"title":"NOISE","subtitle":"one octave of noise.","file":"world.glsl","code":"float terrain(vec2 p) {\n  return 1500.0 * noise(p / 2600.0);\n}"},{"title":"FRACTAL","subtitle":"twelve octaves. mountains.","file":"terrain.js","code":"for (let o = 0; o < 12; o++) {\n  const n = noised(p); d += n.yz;\n  h += a * n.x / (1.0 + dot(d, d));\n  a *= 0.5; p = m2 * p * 2.0;\n}"},{"title":"EROSION","subtitle":"10,485,760 simulated raindrops.","file":"erosion.js","code":"for (let d = 0; d < 10485760; d++) {\n  const cap = max(-dh * speed * water, 0.01);\n  if (sed > cap) deposit(sed - cap);\n  else erode(cap - sed);\n}"},{"title":"MATERIAL","subtitle":"rock. scree. snow.","file":"world.glsl","code":"rock = mix(rock, scree, sediment);\nsnow = smoothstep(.62, .80, normal.y);\nalbedo = mix(rock, vec3(.9, .92, .95), snow);"},{"title":"SUN","subtitle":"a star, 8 light-minutes away.","file":"world.glsl","code":"float sh = softShadow(p + n * 2.0, SUN);\nvec3 sun = sunTrans(p) * SUNI;\ncol = albedo * (sun * max(dot(n, SUN), 0.0) * sh\n      + sky * occ);"},{"title":"ATMOSPHERE","subtitle":"rayleigh · mie · ozone.","file":"world.glsl","code":"const vec3 BR = vec3(5.8e-6, 13.5e-6, 33.1e-6);\nconst vec3 BM = vec3(21e-6);\ncol = col * transmittance + inscatter(ro, rd, t);"},{"title":"CLOUDS","subtitle":"volumetric. perlin-worley.","file":"world.glsl","code":"for (int i = 0; i < 110; i++) {\n  float d = clouds(p, true, HF);\n  acc += Tr * (1.0 - exp(-d * dt));\n  Tr *= exp(-d * dt);\n}"},{"title":"LENS","subtitle":"and a camera.","file":"post.glsl","code":"motionBlur(); depthOfField();\ngodRays();    lensFlare();\nbloom();      filmGrain();"}],"contourColor":"#8fc9ff","trailColor":"#ff8a2a"}'

# or export for apps / editors: mp4 | webm-alpha | prores-alpha | gif | png | poster
node cli/mgl.mjs export terrain-build-3d --as mp4 --props '{"stages":[{"title":"NOTHING","subtitle":"a flat plane.","file":"world.glsl","code":"float terrain(vec2 p) {\n  return 0.0;\n}"},{"title":"NOISE","subtitle":"one octave of noise.","file":"world.glsl","code":"float terrain(vec2 p) {\n  return 1500.0 * noise(p / 2600.0);\n}"},{"title":"FRACTAL","subtitle":"twelve octaves. mountains.","file":"terrain.js","code":"for (let o = 0; o < 12; o++) {\n  const n = noised(p); d += n.yz;\n  h += a * n.x / (1.0 + dot(d, d));\n  a *= 0.5; p = m2 * p * 2.0;\n}"},{"title":"EROSION","subtitle":"10,485,760 simulated raindrops.","file":"erosion.js","code":"for (let d = 0; d < 10485760; d++) {\n  const cap = max(-dh * speed * water, 0.01);\n  if (sed > cap) deposit(sed - cap);\n  else erode(cap - sed);\n}"},{"title":"MATERIAL","subtitle":"rock. scree. snow.","file":"world.glsl","code":"rock = mix(rock, scree, sediment);\nsnow = smoothstep(.62, .80, normal.y);\nalbedo = mix(rock, vec3(.9, .92, .95), snow);"},{"title":"SUN","subtitle":"a star, 8 light-minutes away.","file":"world.glsl","code":"float sh = softShadow(p + n * 2.0, SUN);\nvec3 sun = sunTrans(p) * SUNI;\ncol = albedo * (sun * max(dot(n, SUN), 0.0) * sh\n      + sky * occ);"},{"title":"ATMOSPHERE","subtitle":"rayleigh · mie · ozone.","file":"world.glsl","code":"const vec3 BR = vec3(5.8e-6, 13.5e-6, 33.1e-6);\nconst vec3 BM = vec3(21e-6);\ncol = col * transmittance + inscatter(ro, rd, t);"},{"title":"CLOUDS","subtitle":"volumetric. perlin-worley.","file":"world.glsl","code":"for (int i = 0; i < 110; i++) {\n  float d = clouds(p, true, HF);\n  acc += Tr * (1.0 - exp(-d * dt));\n  Tr *= exp(-d * dt);\n}"},{"title":"LENS","subtitle":"and a camera.","file":"post.glsl","code":"motionBlur(); depthOfField();\ngodRays();    lensFlare();\nbloom();      filmGrain();"}],"contourColor":"#8fc9ff","trailColor":"#ff8a2a"}'

React / Next.js

tsx
import {MotionPlayer} from 'opus-motion-library/web';

<MotionPlayer
  motion="terrain-build-3d"
  props={{
    stages: [
      {
        title: 'NOTHING',
        subtitle: 'a flat plane.',
        file: 'world.glsl',
        code: 'float terrain(vec2 p) {
  return 0.0;
}',
      },
      {
        title: 'NOISE',
        subtitle: 'one octave of noise.',
        file: 'world.glsl',
        code: 'float terrain(vec2 p) {
  return 1500.0 * noise(p / 2600.0);
}',
      },
      {
        title: 'FRACTAL',
        subtitle: 'twelve octaves. mountains.',
        file: 'terrain.js',
        code: 'for (let o = 0; o < 12; o++) {
  const n = noised(p); d += n.yz;
  h += a * n.x / (1.0 + dot(d, d));
  a *= 0.5; p = m2 * p * 2.0;
}',
      },
      {
        title: 'EROSION',
        subtitle: '10,485,760 simulated raindrops.',
        file: 'erosion.js',
        code: 'for (let d = 0; d < 10485760; d++) {
  const cap = max(-dh * speed * water, 0.01);
  if (sed > cap) deposit(sed - cap);
  else erode(cap - sed);
}',
      },
      {
        title: 'MATERIAL',
        subtitle: 'rock. scree. snow.',
        file: 'world.glsl',
        code: 'rock = mix(rock, scree, sediment);
snow = smoothstep(.62, .80, normal.y);
albedo = mix(rock, vec3(.9, .92, .95), snow);',
      },
      {
        title: 'SUN',
        subtitle: 'a star, 8 light-minutes away.',
        file: 'world.glsl',
        code: 'float sh = softShadow(p + n * 2.0, SUN);
vec3 sun = sunTrans(p) * SUNI;
col = albedo * (sun * max(dot(n, SUN), 0.0) * sh
      + sky * occ);',
      },
      {
        title: 'ATMOSPHERE',
        subtitle: 'rayleigh · mie · ozone.',
        file: 'world.glsl',
        code: 'const vec3 BR = vec3(5.8e-6, 13.5e-6, 33.1e-6);
const vec3 BM = vec3(21e-6);
col = col * transmittance + inscatter(ro, rd, t);',
      },
      {
        title: 'CLOUDS',
        subtitle: 'volumetric. perlin-worley.',
        file: 'world.glsl',
        code: 'for (int i = 0; i < 110; i++) {
  float d = clouds(p, true, HF);
  acc += Tr * (1.0 - exp(-d * dt));
  Tr *= exp(-d * dt);
}',
      },
      {
        title: 'LENS',
        subtitle: 'and a camera.',
        file: 'post.glsl',
        code: 'motionBlur(); depthOfField();
godRays();    lensFlare();
bloom();      filmGrain();',
      },
    ],
    contourColor: '#8fc9ff',
    trailColor: '#ff8a2a',
  }}
  playOnView
  loop="auto"
/>

Plain HTML / WordPress

html
<script src="opus-motion.element.js" defer></script>

<opus-motion motion="terrain-build-3d"
  props='{"stages":[{"title":"NOTHING","subtitle":"a flat plane.","file":"world.glsl","code":"float terrain(vec2 p) {\n  return 0.0;\n}"},{"title":"NOISE","subtitle":"one octave of noise.","file":"world.glsl","code":"float terrain(vec2 p) {\n  return 1500.0 * noise(p / 2600.0);\n}"},{"title":"FRACTAL","subtitle":"twelve octaves. mountains.","file":"terrain.js","code":"for (let o = 0; o < 12; o++) {\n  const n = noised(p); d += n.yz;\n  h += a * n.x / (1.0 + dot(d, d));\n  a *= 0.5; p = m2 * p * 2.0;\n}"},{"title":"EROSION","subtitle":"10,485,760 simulated raindrops.","file":"erosion.js","code":"for (let d = 0; d < 10485760; d++) {\n  const cap = max(-dh * speed * water, 0.01);\n  if (sed > cap) deposit(sed - cap);\n  else erode(cap - sed);\n}"},{"title":"MATERIAL","subtitle":"rock. scree. snow.","file":"world.glsl","code":"rock = mix(rock, scree, sediment);\nsnow = smoothstep(.62, .80, normal.y);\nalbedo = mix(rock, vec3(.9, .92, .95), snow);"},{"title":"SUN","subtitle":"a star, 8 light-minutes away.","file":"world.glsl","code":"float sh = softShadow(p + n * 2.0, SUN);\nvec3 sun = sunTrans(p) * SUNI;\ncol = albedo * (sun * max(dot(n, SUN), 0.0) * sh\n      + sky * occ);"},{"title":"ATMOSPHERE","subtitle":"rayleigh · mie · ozone.","file":"world.glsl","code":"const vec3 BR = vec3(5.8e-6, 13.5e-6, 33.1e-6);\nconst vec3 BM = vec3(21e-6);\ncol = col * transmittance + inscatter(ro, rd, t);"},{"title":"CLOUDS","subtitle":"volumetric. perlin-worley.","file":"world.glsl","code":"for (int i = 0; i < 110; i++) {\n  float d = clouds(p, true, HF);\n  acc += Tr * (1.0 - exp(-d * dt));\n  Tr *= exp(-d * dt);\n}"},{"title":"LENS","subtitle":"and a camera.","file":"post.glsl","code":"motionBlur(); depthOfField();\ngodRays();    lensFlare();\nbloom();      filmGrain();"}],"contourColor":"#8fc9ff","trailColor":"#ff8a2a"}'>
</opus-motion>

Compose spec (multi-scene video)

json
{
  "width": 1920,
  "height": 1080,
  "fps": 30,
  "scenes": [
    {
      "motion": "terrain-build-3d",
      "props": {
        "stages": [
          {
            "title": "NOTHING",
            "subtitle": "a flat plane.",
            "file": "world.glsl",
            "code": "float terrain(vec2 p) {\n  return 0.0;\n}"
          },
          {
            "title": "NOISE",
            "subtitle": "one octave of noise.",
            "file": "world.glsl",
            "code": "float terrain(vec2 p) {\n  return 1500.0 * noise(p / 2600.0);\n}"
          },
          {
            "title": "FRACTAL",
            "subtitle": "twelve octaves. mountains.",
            "file": "terrain.js",
            "code": "for (let o = 0; o < 12; o++) {\n  const n = noised(p); d += n.yz;\n  h += a * n.x / (1.0 + dot(d, d));\n  a *= 0.5; p = m2 * p * 2.0;\n}"
          },
          {
            "title": "EROSION",
            "subtitle": "10,485,760 simulated raindrops.",
            "file": "erosion.js",
            "code": "for (let d = 0; d < 10485760; d++) {\n  const cap = max(-dh * speed * water, 0.01);\n  if (sed > cap) deposit(sed - cap);\n  else erode(cap - sed);\n}"
          },
          {
            "title": "MATERIAL",
            "subtitle": "rock. scree. snow.",
            "file": "world.glsl",
            "code": "rock = mix(rock, scree, sediment);\nsnow = smoothstep(.62, .80, normal.y);\nalbedo = mix(rock, vec3(.9, .92, .95), snow);"
          },
          {
            "title": "SUN",
            "subtitle": "a star, 8 light-minutes away.",
            "file": "world.glsl",
            "code": "float sh = softShadow(p + n * 2.0, SUN);\nvec3 sun = sunTrans(p) * SUNI;\ncol = albedo * (sun * max(dot(n, SUN), 0.0) * sh\n      + sky * occ);"
          },
          {
            "title": "ATMOSPHERE",
            "subtitle": "rayleigh · mie · ozone.",
            "file": "world.glsl",
            "code": "const vec3 BR = vec3(5.8e-6, 13.5e-6, 33.1e-6);\nconst vec3 BM = vec3(21e-6);\ncol = col * transmittance + inscatter(ro, rd, t);"
          },
          {
            "title": "CLOUDS",
            "subtitle": "volumetric. perlin-worley.",
            "file": "world.glsl",
            "code": "for (int i = 0; i < 110; i++) {\n  float d = clouds(p, true, HF);\n  acc += Tr * (1.0 - exp(-d * dt));\n  Tr *= exp(-d * dt);\n}"
          },
          {
            "title": "LENS",
            "subtitle": "and a camera.",
            "file": "post.glsl",
            "code": "motionBlur(); depthOfField();\ngodRays();    lensFlare();\nbloom();      filmGrain();"
          }
        ],
        "contourColor": "#8fc9ff",
        "trailColor": "#ff8a2a"
      }
    }
  ]
}

Terrain build (3D) props

18 parameters — change any of them to make the motion yours.

PropDefaultWhat it does
stages[{"title":"NOTHING","subtitle":"a flat plane.","file":"world.glsl","code":"float terrai…list of {title, subtitle, file, code}; index order maps to the fixed build techniques (0 flat … 8 lens)
seed3terrain seed
stageFrames48frames per stage
leadIn6frames before stage 0
flybytruefly past the peak after the build (overlay fades out)
flybyFrames210length of the fly-by
showCodetrueshow the typing code panel
showTitletrueshow the stage title block + progress dashes
sunElevation7final sun elevation in degrees (low = golden hour)
sunAzimuth104final sun azimuth in degrees (90 = from screen right)
snowLine13height above which snow settles (world units, hero peak ≈ 32)
look"natural"natural (default) | contours (illuminated topographic iso-lines on a dark void: no sky, clouds or lens; the build stages still run)
camera"fly"fly (default fly-by) | dive (camera dives from above down the canyon toward the lowest point)
trailfalsea glowing orange route descending the steepest slope during the fly-by (the spark path)
contourColor"#8fc9ff"contours: iso-line colour
contourStep1.6contours: height between lines in world units (hero peak ~ 32)
trailColor"#ff8a2a"trail colour
colors{"rock":"#6e6a66","scree":"#9a948c","grass":"#4f6a3a","snow":"#f2f2f2","clay":"#bcbcbc"…rock / scree / grass / snow / clay / sun / zenith / horizon / cloudShadow / cloudLight

Notes & credits

Technique sources:

  • video8 0:04-0:38