Search code examples
javascriptthree.js3daframevirtual-reality

Lights in A-Frame have striped artifacts depending on distance from them


I am using the latest A-Frame 1.0.4 and I have tried both with spot light (in the picture attached) and with direct light.

The shadowBias is set to -0.0001, changing it affects the artifact only slightly.

If I set the shadowMapHeight and shadowMapWidth to 1024 the artifact shrinks back a bit from the source of light. To have it completely disappear I have to put 4096, which is a bit too much, performance-wise. I can't have all lights with a 4k shadow map.

A similar effect has increasing the shadowCamera far, from 500 to 5000 for example. but this introduces wrong shadows, distant from the objects (even if I tweak the shadowBias).

Am I doing something wrong? Why the lights with default settings have these problems? Does it perhaps depend on the models ?

Any clue would be appreciated

artifact


Solution

  • I was able to find the culprit! My models are double sided, and this resulted into the front face casting shadow on the back face together with the back face casting shadow on the front face, hence the striped glitch.

    After having a look at three.js - material and confirming with material.side that it was actually double sided, I used material.shadowSide = THREE.BackSide to force the backside to cast shadow onto the frontside, regardless of the model/material double side property. This solved the glitch!

    Of course be mindful that if a model has wrong normals i.e. don't facing towards the outside / inverted , that face will have the glitch again.