Abrupt change in shadow effects when using ShadowOnlyMaterial

When I was playing with shadows I encountered a strange issue with ShadowOnlyMaterial, please refer to this playground: https://playground.babylonjs.com/#ZT8BKT#89

There is an abrupt change in shadow effects between camera beta Math.PI/15 and Math.PI/14. This does not happen if the ground uses StandardMaterial (line 22).

Interestingly, if I change the ball visibility to 1, this artifact disappears, however I need to see the tube inside the ball so that does not work.

Would highly appreciate any insight on this. Thanks!

It’s an ordering problem between the ground and the ball: sometimes the ground is displayed before the ball, and sometimes it’s the reverse. That’s because both objects are considered transparent, which is sometimes a pain to deal with (see Transparent Rendering | Babylon.js Documentation).

In your case, you can force the ground to be displayed first by setting ground.alphaIndex = 0;:

1 Like

This nailed it! Thank you very much for the explanation and solution.