webdevpuneet.com

Three.js Synthwave Terrain — Infinite Retro Wireframe Grid Landscape

Three.js Synthwave Terrain · Animations · Plain HTML, CSS & JS · Live preview

CategoryAnimations

Copy & paste

Source Code

Requires
<canvas id="synthCanvas"></canvas>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Two-tile relay scroll: an endless-looking terrain built from exactly two geometries, not infinite regeneration
Sine-wave height field: the same overlapping-wave technique as a water surface, applied once as static terrain
Seamless tile boundaries: both grids share one height formula so their edges align with no visible gap
Exponential fog: THREE.FogExp2 dissolves the horizon smoothly and conceals each tile's reset moment
Canvas-drawn sun sprite: a radial-gradient glow generated on the fly with 2D canvas, no image file needed
Wireframe as aesthetic: a deliberate retro-computer-graphics look, not a geometry debugging leftover
Fixed, tilted camera: motion illusion comes entirely from scrolling terrain, not camera movement
Loaded entirely from a CDN: no npm install, bundler, or build step required

About this UI Snippet

How to Build an Infinite Synthwave Wireframe Terrain in Three.js

Screenshot of the Three.js Synthwave Terrain snippet rendered live

The Three.js Synthwave Terrain snippet recreates the retro-futuristic wireframe landscape aesthetic — a glowing pink grid stretching to a foggy horizon under a gradient sun — using two seamlessly-looping wireframe planes, exponential fog, and a canvas-drawn sprite texture, all with core Three.js loaded from a CDN and zero external image assets.

Two tiles, not one endless plane

Rendering a genuinely infinite terrain would require regenerating geometry forever, which isn't practical. Instead, the snippet builds exactly two identical wireframe grid tiles, placed back-to-back along the Z axis. Every frame, both tiles move slightly toward the camera; the moment either tile has traveled a full tile-length past the camera, its Z position snaps backward by *two* tile-lengths — placing it immediately behind its partner again, invisible to the viewer since it happens off-screen at the far end of the fog. This two-tile relay is the standard, cheap technique behind endless-scrolling roads, rivers, and terrain in countless games and demos.

The height field comes from the same sine-wave technique as water

Before the scrolling animation ever starts, each grid's vertices are displaced once using Math.sin(x * freq) + Math.cos(z * freq) — the exact same overlapping-wave technique used in the particle wave snippet, just applied once to build a static rolling-hills shape rather than recalculated every frame for a moving ripple. Because both tiles run through the identical height formula, their edges match up perfectly where they meet, with no visible seam or height mismatch at the boundary.

Exponential fog does the atmospheric heavy lifting

THREE.FogExp2 fades objects toward the fog color based on an exponential falloff with distance, rather than the more clinical linear fog. This is what makes the wireframe grid's far edge dissolve smoothly into the background instead of appearing to end abruptly at a hard clipping line — and it's also doing double duty by visually hiding the exact moment each tile snaps back into position at the far end of the scene.

A sun sprite drawn with 2D canvas, not an image file

The glowing sun is a THREE.Sprite — a flat, camera-facing quad — textured with a CanvasTexture built from a plain 2D <canvas> radial gradient (warm center fading through pink to fully transparent). This is a genuinely useful technique beyond this one snippet: any soft glow, particle sprite, or gradient billboard in Three.js can be generated on the fly this way, entirely in JavaScript, with no image file to host or load.

Wireframe as an aesthetic choice, not a debugging leftover

Setting wireframe: true on a MeshBasicMaterial is often used for debugging geometry — here it's the entire point. Combined with a saturated magenta color and additive-feeling transparency, the wireframe grid reads immediately as the classic retro-computer-graphics look associated with 1980s synthwave album art and film title sequences.

A tilted, fixed camera, not a free-look one

The camera never moves or rotates on its own beyond a small fixed downward tilt set once at startup — the *illusion* of forward motion comes entirely from the grid tiles scrolling toward the camera, not from the camera actually traveling through space. This is a cheaper and more controllable approach than moving the camera along a path, since the terrain's motion speed is the only variable that needs adjusting.

Where this technique extends

The two-tile relay-scroll pattern generalizes to any endless-terrain effect — rivers, roads, star tunnels, or infinite corridors. Pair this snippet with a starfield warp for a full synthwave "drive into space" sequence, or contrast its retro wireframe aesthetic against the smooth, lit surface of the particle wave.

Step by step

How to Use

  1. 1
    Load the Three.js CDNAdd three.min.js from the CDN panel — no add-ons are required for this snippet.
  2. 2
    Paste HTML, CSS, and JSThe grid terrain and glowing sun appear immediately, scrolling toward the camera endlessly.
  3. 3
    Watch the seamless loopFog hides the moment each tile resets, so the scroll appears to continue forever with no visible seam.
  4. 4
    Tune scroll speedAdjust the SPEED constant for a slower cruise or a faster, more dramatic drive.
  5. 5
    Retint the sceneChange the grid color, fog color, and sun gradient stops together for a different neon palette.
  6. 6
    Resize the windowRenderer size and camera aspect ratio update automatically.

Real-world uses

Common Use Cases

Retro and synthwave-themed landing pages
An instantly recognizable 1980s-inspired backdrop for music, gaming, or nostalgia-driven brand sites.
Music and event visuals
Pairs naturally with synthwave, vaporwave, or retro-electronic music branding and album promotion pages.
Teaching seamless scroll-loop techniques
A focused, minimal example of the two-tile relay pattern used across countless endless-runner and driving effects.
Racing or endless-runner game menus
A ready-made scrolling terrain backdrop for a game's title screen or menu before gameplay begins.
Portfolio and agency showpieces
A striking, technically interesting background that stands out from typical gradient or particle hero effects.
Video intro and transition sequences
Use as a looping background video substitute for intros, loading transitions, or between-section breaks.

Got questions?

Frequently Asked Questions

Exactly two identical wireframe grid tiles are placed back-to-back along the Z axis. Every frame both tiles move slightly toward the camera; the moment a tile has traveled a full tile-length past the camera, its position snaps backward by two tile-lengths, placing it immediately behind its partner again. Because that reset happens far away in the fog, it is never visibly noticeable.

Both tiles are built by the exact same buildGrid() function, running the identical sine-and-cosine height formula on the same geometry dimensions. Because the height at any given X/Z coordinate is always calculated the same way regardless of which tile it belongs to, the edge where two tiles meet lines up perfectly with no height mismatch.

THREE.FogExp2 fades visibility based on an exponential falloff with distance rather than a straight linear ramp, which produces a smoother, more natural-looking dissolve into the horizon. It also conveniently hides the exact far-distance point where each tile's position resets, since that area is already heavily obscured by fog.

A plain 2D canvas element is created in memory (never appended to the page), a radial gradient is painted onto it from a warm center color fading through pink to fully transparent, and that canvas is wrapped in a THREE.CanvasTexture applied to a Sprite material. This produces a soft, glowing image entirely through code, with no external asset to host or load.

Yes. The SPEED constant controls how much each tile moves toward the camera every frame — raise it for a faster, more dramatic drive-through feel, or lower it for a slow, ambient cruise.

Yes. Click JSX for a React component, Vue for a Vue 3 SFC, Angular for a standalone component, or Tailwind for a React + Tailwind CSS utility-class version. Build the grid tiles and sun sprite inside a mount effect so the geometry and canvas texture are only created once, and call renderer.dispose() plus cancelAnimationFrame on cleanup.