Env IBL on Lambert vs Phong (r183)

Side-by-side material comparison showing environment-based lighting reflections on `MeshLambertMaterial` and `MeshPhongMaterial` using a live cubemap probe.

Key topics: three.js ibl, lambert material, phong material, scene.environment, r183

Overview

Image-based lighting (IBL) lights a scene from a captured environment rather than from individual lamps, so surfaces pick up colour and soft illumination from everything around them. It used to be associated only with physically based materials, but recent Three.js versions let the classic MeshLambertMaterial and MeshPhongMaterial use scene.environment too. This demo compares them side by side under a live environment probe.

How it works

A CubeCamera continuously captures the surroundings, including rotating coloured emitters, into a cube render target, which is assigned to scene.environment. Every material that supports environment lighting then samples it:

  • Lambert uses the environment for diffuse lighting only. The surface takes on the average colour of the light around it, tinting gently as the emitters rotate.
  • Phong adds a specular reflection of the environment, controlled by its shininess, so you see coloured highlights moving across the surface in addition to the diffuse tint.

A GUI slider sets the environment intensity for both materials equally, so the comparison stays fair. Because the emitters move, the probe updates every frame and the effect of IBL is obvious; with a static HDRI the lighting would be just as rich but unchanging.

Exploring the demo

Watch the colours sweep across both objects as the emitters rotate. The Lambert object changes tint softly and evenly; the Phong object also shows sharper coloured reflections. Turn the intensity to zero to see how dull both materials look with only direct lights, then raise it to see how much IBL contributes.

Practical advice

Lambert and Phong are cheaper than MeshStandardMaterial, so this is a useful option for large numbers of objects or lower-end devices that still need to sit naturally in an environment. For realistic scenes, prefer prefiltered HDRIs processed with PMREMGenerator. See the materials gallery for a lights-only comparison, environment maps for reflective PBR materials, and light probes for localised environment capture.

What this code does

- Global Environment Lighting: a live cube camera captures surrounding emissive objects and feeds `scene.environment`.
- Lambert + IBL: demonstrates how Lambert material now participates in environment lighting workflows.
- Phong + IBL: classic Phong model shown side-by-side as a reference for specular behavior.
- Real-Time Probe Update: rotating emitters continuously change reflected colors to make IBL response obvious.
- Intensity Control: GUI slider adjusts environment influence equally for both materials.
- Practical Use: useful for choosing legacy material models while still using modern image-based lighting setups.

Continue Learning

JavaScript Implementation

ES6+
import * as THREE from 'three'

const cubeRT = new THREE.WebGLCubeRenderTarget(256)
const cubeCamera = new THREE.CubeCamera(0.1, 100, cubeRT)

// Render environment probes from helper scene/objects.
cubeCamera.update(renderer, scene)

// Use the captured env map globally.
scene.environment = cubeRT.texture

const lambert = new THREE.Mesh(
  new THREE.SphereGeometry(0.85, 48, 48),
  new THREE.MeshLambertMaterial({ color: 0xffffff })
)
const phong = new THREE.Mesh(
  new THREE.SphereGeometry(0.85, 48, 48),
  new THREE.MeshPhongMaterial({ color: 0xffffff, shininess: 120 })
)
scene.add(lambert, phong)

Related demos

Trending this week

Most popular