webdevpuneet.com

Three.js Scroll Planet Approach — Orbit Into a Sunrise

Three.js Scroll Planet Approach · Scroll · Plain HTML, CSS & JS · Live preview

About this UI Snippet

How to Build a Scroll-Driven Planet Approach With Three.js and GSAP

Screenshot of the Three.js Scroll Planet Approach snippet rendered live

The Three.js Scroll Planet Approach snippet flies the camera from deep space into low orbit around Thalassa, a fictional ocean world, and ends on a sunrise breaking over the planet's limb. GSAP's ScrollTrigger scrubs one 0–1 progress value. Every other quantity is derived from it each frame: camera distance, orbit angle, view direction, altitude and velocity readouts, captions and mission phase. It is the "arrival" counterpart to the starfield warp: instead of racing past stars forever, the scroll ends somewhere.

A planet generated in the browser

Nothing is downloaded. Three equirectangular canvas textures are painted at load time by sampling 3D value-noise fBm on the unit sphere, so they wrap with no seam. The day map uses domain-warped elevation for coastlines and thresholds it into deep and shallow ocean, sand, grass, forest, desert, rock and snow, with noisy polar ice caps. A second "data" map stores city lights in red and an ocean mask in green. A third map is banded cloud cover used as an alphaMap.

A day/night shader

The planet uses a small ShaderMaterial. Diffuse light follows the sun direction, and the ocean mask gets a Blinn-Phong glint so seas sparkle where the sun reflects. On the night side city lights fade in, broken into fine speckle by a per-texel hash so they read as cities rather than blobs. A narrow orange band marks the terminator, and a fresnel term adds blue haze at the limb. Clouds are a slightly larger Lambert sphere lit by the same sun, so they darken on the night side too.

An atmosphere that glows like one

The atmosphere is a back-face shell 9% larger than the planet with additive blending. Its intensity comes from the view-space normal, so it is brightest right at the limb and fades outward. Each fragment also checks the sun direction: the sunlit side glows blue, the dawn edge turns warm, and the night side stays almost dark. That is what makes the final sunrise frame work.

A flight path that ends on a sunrise

Distance follows a braking curve, D1 + (D0 − D1)(1 − p)^2.4, so the planet grows fast at first and settles on arrival. The camera also swings 1.35 radians around the planet and descends from above the orbital plane. That moves the view from the lit face, across the terminator and over the night side. For the last third of the scroll the view direction blends from "look at the planet" to "look along the horizon toward the sun". camera.up blends from world Y to the local radial direction, so the horizon ends level. The sun is placed just beyond the limb from the final position, a sprite with a large halo that the planet hides until it clears the horizon.

Story and HUD

A title card opens the scene. Captions cross-fade at set progress points, and a glass HUD shows the mission phase, altitude, velocity (braking from 14 to 7.6 km/s), and a progress bar that turns gold at orbit insertion. Planet spin, cloud drift and the textured moon's orbit run on clock time, so the scene keeps moving when scrolling stops. Scrolling back up reverses everything exactly, as in the scroll camera path.

What's included

Features

Procedural day, city-light and cloud maps from 3D noise on the sphere — seamless and zero downloads
Day/night ShaderMaterial with ocean sun glint, speckled city lights, terminator glow and limb haze
Sun-aware atmosphere shell: blue on the day side, warm at dawn, dark at night
Braking-curve approach that swings around the planet from the lit face to the night side
Final camera turn to the horizon with a level up vector, ending on a sunrise over the limb
Sun sprite with halo that the planet occludes, a textured moon, a coloured starfield and soft nebula glows
Mission HUD with phase, altitude, velocity and progress, plus story captions and an intro title card
Fully reversible: every state is a function of one scrubbed value plus clock-driven idle motion

Step by step

How to Use

  1. 1
    Load the three CDN scriptsAdd three.min.js, gsap.min.js, and ScrollTrigger.min.js in that order before the snippet JS.
  2. 2
    Paste HTML, CSS, and JSA pinned starfield opens with the "Approach Thalassa" title card, the small planet and its moon, and a HUD reading 168,000 km.
  3. 3
    Scroll to descendThe planet grows and turns, the terminator sweeps across the oceans, and captions and the mission phase update as you go.
  4. 4
    Cross the night sideAround 70% the city lights glow across the dark hemisphere while the atmosphere rim brightens on the sunlit limb.
  5. 5
    Arrive in orbitThe camera turns to the horizon and the sun rises over the edge of the planet. The HUD turns gold: orbit established.
  6. 6
    Make your own worldEdit the colour constants (DEEP, GRASS, SNOW…) or the sea-level offset in the day map to change continents, and SUN_A to move the dawn.

Real-world uses

Common Use Cases

Space and aerospace landing pages
Open a satellite, launch-provider, or space-data product page with an arrival sequence that ends exactly where your content begins.
Sci-fi game and metaverse promos
Use the approach as a "destination reveal" before showing gameplay, pairing naturally with a starfield warp intro above it.
Story-driven scrollytelling
Make arrival at a world chapter one of a scroll story, with the sunrise as the reveal, then hand off to a scroll camera path for the next scene.
Teaching shaders and procedural textures
A compact, readable example of noise-painted equirectangular maps, a day/night fragment shader, and a sun-aware atmosphere glow.
Portfolio hero with a destination metaphor
Frame your work as "arriving somewhere" — the orbit-established endpoint makes a natural transition into a project grid.
Ambient generative-art pages
Let the slow spin, drifting clouds, and orbiting moon carry the scene between scrolls, like the idle motion in galaxy formation.

Got questions?

Frequently Asked Questions

Canvas textures are painted at load time. For each pixel the latitude and longitude become a point on the unit sphere, and 3D fBm noise at that point gives elevation and moisture, which map to ocean, sand, forest, desert, rock and snow. Sampling in 3D means the left and right edges match, so there is no seam. City lights and an ocean mask go into a second map.

The planet shader computes dot(normal, sunDirection). Where it is negative the day colour fades to near black and the city-light channel is added in a warm orange. A hash of the texel position breaks each lit area into fine speckle, so close up it reads as many small towns instead of a smooth blob.

The sun direction is chosen so that, from the final orbit position, it sits just above the limb. In the last third of the scroll the view blends from the planet centre to a horizon direction facing the sun, and camera.up blends to the local radial so the horizon lies level. The sun sprite is depth-tested, so the planet hides it until it clears the edge.

The tween stays ease "none" so one linear 0–1 value drives everything. Distance uses a braking power curve, orbit angle uses a softer one, and the camera turn only starts at 62%. Each property gets its own easing from the same scrub, which a single eased tween cannot do.

Yes. Use the JSX, Vue or Angular export. Build the scene in a mount effect against a canvas ref; the textures take a moment to generate, so do it once. On cleanup kill the ScrollTrigger, dispose geometries, materials and canvas textures, and call renderer.dispose().

Copy & paste

Source Code

<section class="pla-stage" id="plaStage">
  <canvas id="plaCanvas"></canvas>
  <div class="pla-vignette"></div>
  <div class="pla-intro" id="plaIntro">
    <p class="pla-kicker">Destination · ocean world</p>
    <h2>Approach Thalassa</h2>
    <p class="pla-hint">Scroll to begin descent <span class="pla-mouse"><i></i></span></p>
  </div>
  <p class="pla-caption" id="plaCaption"></p>
  <div class="pla-hud">
    <p class="pla-phase"><span class="pla-dot"></span><b id="plaPhase">Deep space</b></p>
    <div class="pla-stats">
      <div><small>Altitude</small><b><span id="plaDist">168,000</span> km</b></div>
      <div><small>Velocity</small><b><span id="plaVel">0.0</span> km/s</b></div>
    </div>
    <div class="pla-bar"><i id="plaBar"></i></div>
  </div>
</section>
<section class="pla-bottom">
  <p class="pla-kicker">Orbit established</p>
  <h2>Welcome to Thalassa. Mind the sunrise.</h2>
</section>

Extend with AI

Take This Snippet Further With AI

You do not need to work out sphere-mapped noise textures, day/night shading, or the sunrise camera turn on your own — this snippet already does all three. Paste its HTML, CSS, and JS into an AI assistant like Claude and ask it to explain how the equirectangular maps wrap without a seam, how the atmosphere shell picks blue or warm colours, or how camera.up is blended so the horizon ends level. The same assistant can extend it: add a ring system with a shadow, cloud shadows on the surface, a lens-flare streak when the sun clears the limb, a ship that slides into frame at orbit, or a second destination planet. Treat the code as a starting point to interrogate and reshape, not a finished artifact.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a "scroll-scrubbed planet approach that ends on a sunrise" in plain HTML, CSS, and JavaScript using Three.js (r128) and GSAP's ScrollTrigger, all from a CDN (no bundler, no build step).

Requirements:
- A pinned full-viewport section with a transparent WebGLRenderer over a dark-blue radial-gradient background, a vignette, and a PerspectiveCamera (55° FOV, 72° when the aspect is below 0.8).
- Procedural textures painted on canvases at load: 3D value noise + fBm sampled on the unit sphere for each equirectangular pixel. Day map (1024×512): domain-warped elevation → deep/shallow ocean, sand, grass/forest by moisture, desert in dry low latitudes, rock, snow, noisy polar ice. Data map: red = city lights on habitable land, green = ocean mask. Cloud map: banded fBm used as an alphaMap. Moon map (256×128) with crater noise.
- The planet (radius 10) as a ShaderMaterial: diffuse from dot(N, sunDir), a Blinn-Phong ocean glint, city lights on the night side broken into speckle with a per-texel hash, a narrow orange terminator band, and blue fresnel haze at the limb.
- Clouds: a sphere at 1.012R with a white MeshLambertMaterial, alphaMap = cloud map, transparent, depthWrite false.
- Atmosphere: a BackSide additive shell at 1.09R whose glow comes from the view-space normal (brightest at the limb) and is tinted by the sun: blue by day, warm at the dawn edge, nearly dark at night.
- Sun as two additive sprites (core + large halo) far along the sun direction and depth-tested so the planet hides it; a DirectionalLight from the same direction; a textured moon on a clock-driven orbit; 3000 coloured round-sprite stars; three large faint nebula sprites.
- Flight: one GSAP tween (ease "none") scrubbing p 0→1 (pin, scrub 1, end +=500%). Distance = 13.2 + (150 − 13.2)(1 − p)^2.4; the orbit angle swings 1.35 rad from a sunlit view to a final position where the sun sits just past the limb; height falls from about 22 to 0.6.
- From p = 0.62 the view direction blends from the planet centre to a direction along the horizon toward the sun (tilted about 0.5 rad down), and camera.up blends from world Y to the local radial, so the final frame is a level horizon with the sun rising over it.
- UI: an intro title card ("Approach Thalassa"), story captions cross-fading at set progress points, and a glass HUD with a phase label, altitude in km, velocity braking from 14 to 7.6 km/s, a progress bar, and a gold "orbit established" state. Mobile puts the HUD at the top.
- Scrolling back must reverse everything exactly.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.