How to ensure that a light doesn't lit walls behind corner?

- 1 answer

Ad

Good day, I'm playing with webgl using Babylon JS and I need an advice concerning lights. I created a test cave and I placed a torch (BABYLON.PointLight) on one wall. But the light lits also walls that is behind the corner. See screenshot:

enter image description here

var light = new BABYLON.PointLight("light1", new BABYLON.Vector3(x, y, z), scene);
light.intensity = 0.5
light.range = 50;

The cave is not a single mesh but it's made of individual rectangular faces. How can I ensure that the lit doesn't lit walls behind the corner please?

Thank you in advance. Vojtech

Ad

Answer

Ad

Lights only colors pixels based on the direction from the pixel to the light, the normal (surface angle) of the pixel and the viewing direction. Thus, lights by themselves do not taken into account whether the light source actually reached the pixels and that must be calculated separately with a shadowing algorithm.

Ad
source: stackoverflow.com
Ad