Skip to content

WebGPURenderer: ProjectorLight unintentionally emits light from its back side #31461

@ycw

Description

@ycw

Description

Projectorlight is unintentionally illuminating areas behind it, see screenshots

Reproduction steps

  1. Add a ProjectorLight (angle<90deg)
  2. Set it facing towards -x;
  3. You should see the ProjectorLight is illuminating areas behind it (+x)

Code

import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

const renderer = new THREE.WebGPURenderer()
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, 2, 0.1, 100)
const controls = new OrbitControls(camera, renderer.domElement)

scene.background = new THREE.Color('skyblue')
camera.position.set(0, 2, 2)
scene.add(new THREE.AxesHelper())

{ // ground
    const geom = new THREE.PlaneGeometry(10, 10).rotateX(Math.PI / -2)
    const mat = new THREE.MeshStandardMaterial()
    const mesh = new THREE.Mesh(geom, mat)
    mesh.position.y = -0.1
    scene.add(mesh)
}

{ // light
    const light = new THREE.ProjectorLight('white', 10, 2, Math.PI / 10, 0, 2)

    light.target = new THREE.Object3D()
    light.add(light.target)
    light.target.position.set(-1, 0, 0)
    light.position.set(0, 0, 0)

    scene.add(light)
    scene.add(new THREE.SpotLightHelper(light))
}

renderer.setAnimationLoop(() => {
  renderer.render(scene, camera)
  controls.update()
});

function resize(w, h, dpr = devicePixelRatio) {
  renderer.setPixelRatio(dpr)
  renderer.setSize(w, h, false)
  camera.aspect = w / h
  camera.updateProjectionMatrix()
}
addEventListener('resize', () => resize(innerWidth, innerHeight))
dispatchEvent(new Event('resize'))
document.body.prepend(renderer.domElement)

Live example

n/a

Screenshots

Image

Version

dev

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions