light-threejs-backgrounds

Created about 4 hours ago

attributes
additional_license_urlshttps://github.com/MengTo/Skills/blob/2f8cb46167bec49ee3c4a6ca37972fc065b6b47e/agent-skills/web-design/light-threejs-backgrounds/demo/assets/THREE-LICENSE.txt
descriptionBuild a real Three.js background with directional light, atmospheric depth and restrained pointer parallax while keeping live foreground headings and controls readable. Use for cinematic landing page backgrounds.
import_scopesignals-cleared-supporting-files
licenseMIT
license_urlhttps://github.com/MengTo/Skills/blob/2f8cb46167bec49ee3c4a6ca37972fc065b6b47e/LICENSE
namelight-threejs-backgrounds
publisherMengTo
repository_urlhttps://github.com/MengTo/Skills
source_urlhttps://github.com/MengTo/Skills/blob/2f8cb46167bec49ee3c4a6ca37972fc065b6b47e/agent-skills/web-design/light-threejs-backgrounds/SKILL.md
upstream_copyrightCopyright (c) 2026 Meng To, Copyright © 2010-2025 three.js authors
upstream_revision2f8cb46167bec49ee3c4a6ca37972fc065b6b47e

Light Three.js Backgrounds

Compose the scene around a reserved area for the headline. Use depth to shape the light in the street, then a separate translucent layer to keep text contrast stable as the camera moves.

Compose from the type outward

  1. Lay out real HTML text and buttons at desktop and mobile widths first. Mark the full bounding box including focus rings. Start with a 44% copy column inset 6% on desktop. Move the copy above the subject on mobile.
  2. Place a decorative canvas behind it in an isolated stacking context. Give the canvas pointer-events: none and listen on its parent. Set a matching still as the background until the first successful render. The example layout keeps text independent of the renderer.
  3. Place crisp signs and dark foreground structures on the far edge. Use middle-distance wires, a train or an awning to reveal parallax. Recede into pale distant blocks around the vanishing point. Use instancing for repeated windows and railings. The city module shows the scene layout and the render loop. This technique assumes real depth layers. A sky-only scene can use a simpler gradient and clouds.

Shape the light

  • Start with a warm backlight from the upper right. The reference direction is the normalized vector (.43, .65, −.72). Balance it with cooler fill. Keep the brightest shaft away from thin lettering.
  • For a deeper scene, render opaque color and depth together. Sample sun visibility along the view ray only up to the nearest opaque surface. Accumulate light at reduced resolution, then use depth agreement to avoid bleeding across roof edges. See district-light.js. Bake static shadows and a small reflection probe once. Refresh after geometry or context changes.
  • Put a paper-colored gradient between scene and copy. The example starts near 94% opacity on the left, reaches 86% at 28% width and falls to 29% at 65%. Change the direction to top-down when the copy stacks. Reverse the luminance for white type on dark backgrounds. Use the comparison button to isolate this layer.

Keep motion quiet

Damp normalized pointer movement at 3 per second. The demo moves the camera up to 0.76 scene units sideways and 0.27 vertically while the target moves only 0.18 and 0.06. Reframe for portrait screens. Never move the copy with the camera. Cap the drawing buffer by both device pixel ratio and area. The demo budgets 2.8 million pixels and updates at about 30 fps. Reduce volumetric samples before softening the type.

Check the worst frame

Inspect the whole text box with the camera at both extremes and with moving geometry behind it. Aim for at least 4.5 to 1 contrast for body copy and 3 to 1 for large type. Increase local gradient coverage if a dark roof crosses a letter. Check keyboard focus, touch scrolling and the still fallback with WebGL unavailable. Render a settled frame for reduced motion and stop the loop when the tab or section is hidden.

Run the example

From this skill folder, run python3 -m http.server 4173 --bind 127.0.0.1 -d demo and open the local demo. The demo runs without a build or remote assets. See the preview and recreation prompts.

Adapted from the Stillhertz landing page. Keep the host project's typography, subject and layout. Bring over only the relevant technique. The sample is a single page. For a routed application, cancel animation frames, remove listeners, disconnect observers and dispose GPU resources on unmount.


Copyright (c) 2026 Meng To Copyright © 2010-2025 three.js authors

The license files are attached. MIT · MIT

The attached ZIP contains the pinned supporting files cleared for import. Applicable license notices are attached or included when cleared.

Like how this is organised?

Build your own Memory tree on knowen.md: notes, decisions and tasks in one connected markdown graph, shared with your team and your AI agents.