HOW TO ADD LIGHTING
TO A THREE.JS SCENE

By Shane Brumback · · Updated · Free Three.js tutorial · Level 1

To light a Three.js scene, add a soft fill light such as AmbientLight or HemisphereLight, one main DirectionalLight for the sun, and PointLight or SpotLight for local glows, then turn on shadows. This campsite uses all four: the sun, sky fill, a flickering campfire and a lamp-post spotlight.

A beginner walkthrough of every common light in Three.js 0.160, built only from simple shapes. The campsite behind this page is the live demo: watch it slide from day to dusk as the fire and lamp take over. The full copy-paste source is below.

✓ FREE Level 1 · Beginner 4 light types Soft shadows Day to dusk
See it live

LIVE DEMO

The campsite behind this page is a live Three.js scene. Launch the full-screen demo to drag to orbit and scroll to zoom around the tent, the campfire and the lamp post while the sun sets. Launch asks for a free Google sign-in first. Press Esc or Exit to return.

Free Google sign-in · Orbit: drag · Zoom: scroll · Esc to exit

READY FOR ENDLESS TERRAIN?

This Level 1 campsite sits on a small circle of grass under one sun. The Level 3 premium Terrain LOD tutorial lights endless hills with sand, grass, rock and snow blended in an onBeforeCompile shader, with LOD skirts, worker chunks and grass that follows you. Members unlock the full code; sign in to reveal it.

Three.js terrain LOD and splat shader premium tutorial
See the Level 3 Tutorial

How Lighting Works in Three.js

A light in Three.js is an invisible object that tells materials how bright and what color each surface should be. Materials like MeshStandardMaterial stay black until a light reaches them, while MeshBasicMaterial ignores lights, which is why the flame and the bulb use it to look like they glow.

Real places mix lights, so this demo maps each type to something you already know: AmbientLight and HemisphereLight are the sky, DirectionalLight is the sun, PointLight is the campfire, and SpotLight is the lamp. New to Three.js? Start with the spinning cube starter or rendering a 3D cube, then come back here.

How It Works

  1. Set up the scene, camera and renderer. We make an empty 3D world, a camera that looks at it, and a renderer that draws it.
  2. Fill the sky with AmbientLight and HemisphereLight. A scene with no light is pitch black, so first we add soft light that comes from everywhere.
  3. Add the sun with a DirectionalLight. The sun is so far away that all its rays are parallel, which is exactly what a DirectionalLight does.
  4. Build the ground, trees and rocks. Lights need something to land on.
  5. Pitch the tent. A four-sided cone makes a perfect tent.
  6. Light the campfire with a PointLight. A PointLight shines in every direction from one spot, like a bulb or a flame.
  7. Hang a SpotLight in the lamp post. A SpotLight is a cone of light, like a flashlight or a street lamp.
  8. Add drifting low-poly clouds. A few puffy clouds make the sky feel alive, and they show the sunset colours beautifully.
  9. Animate day to dusk and the flicker. Every frame we slowly lower the sun, darken the sky, and turn the campfire and lamp up as night falls.

The detailed code breakdown and the full copy-paste file are below. Every step is an exact excerpt of the full file, and the full file is the same code as the live demo.

Want to add motion next? See creating and animating simple 3D objects, or grow the meadow with the endless procedural grass tutorial.

Frequently Asked Questions

What are the main light types in Three.js?

Three.js has AmbientLight (even light everywhere), HemisphereLight (sky and ground colors), DirectionalLight (parallel rays like the sun), PointLight (all directions from one point, like a bulb or fire), SpotLight (a cone like a flashlight) and RectAreaLight (a glowing panel).

Why is my Three.js scene completely black?

Either there are no lights, or your material needs light. MeshStandardMaterial, MeshPhongMaterial and MeshLambertMaterial are dark without a light, while MeshBasicMaterial ignores lights. Add an AmbientLight or HemisphereLight plus a DirectionalLight to start.

How do I turn on shadows in Three.js?

Set renderer.shadowMap.enabled to true, set castShadow to true on the light and on the objects that block it, and set receiveShadow to true on the ground. Only DirectionalLight, PointLight and SpotLight can cast shadows.

Why are my PointLight and SpotLight so dim in Three.js r160?

Since r155 Three.js uses physically correct light units by default, so point and spot intensities are in candela and fade with distance squared when decay is 2. Use larger intensities, such as 20 to 70 in this demo, or move the light closer.

How do I make a light flicker like fire?

In the render loop multiply the PointLight intensity by a flicker value built from two fast sine waves plus a small Math.random() amount, and scale the flame mesh by the same value so the glow and the flame move together.

How do I add cheap low-poly clouds in Three.js?

Use one InstancedMesh of flat-shaded IcosahedronGeometry puffs squashed on the y axis, a few puffs per cloud, move each cloud slowly along x and wrap it around, and lerp the material color with the same dusk value that drives the sky so the clouds turn pink at sunset and blue at dusk.

Why do I need to sign in to launch the live demo?

The tutorial and its full code are free to read. The full-screen Live Demo asks for a free Google sign-in first, the same gate used across the site, so I know who is learning from these tutorials.

Play It and Keep Learning

Sun, shadows and fire light like this power Super Soldier Battle, free in your browser. Browse every Three.js tutorial, read the articles, or search the site.

Need Three.js lighting or WebGL work? I take freelance and contract work: contact me.

Play Game