Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the shadow in the wrong place? (Three.js)

I have a green plane, and a red cube over it. The light is a directional light.

shadow

Why is the shadow in the wrong place? Code: http://jsfiddle.net/pD8dn/


Edit:

If I change the light.shadowBias then the shadow on the plane is correct, but the shadow is on the cube incorrect:

shadow

http://jsfiddle.net/pD8dn/4/

Thanks in advance,

like image 444
eqiproo Avatar asked Jun 20 '12 11:06

eqiproo


1 Answers

This is one of the most common artefacts for shadow maps, it's called "Peter Panning".

A workaround is to add some small bias for depth testing:

light.shadowBias = 0.001;

Exact value of the bias needs to be tuned for each scene (and unfortunately sometimes you'll not be able to get rid of all artefacts everywhere, tuning shadow maps is more art than science).

This is what works for your example:

http://jsfiddle.net/pD8dn/2/

like image 137
alteredq Avatar answered Sep 23 '22 12:09

alteredq