How to fix strange glitches in shadows (shadow acne) on textured objects


I am trying to get shadows with panda3d-simplepbr in my project but I am having issues with the result and I don’t understand what is happening.

Maybe you can help me on this! :wink:

Here are the shadows-related parts of my code:


slight = direct.showbase.ShowBase.Spotlight("ShadowLight")
slight.setAttenuation((0, 0, 0.025))
slight.set_shadow_caster(True, 1024, 1024)
slight.setColor((1, 1, 1, 1))
lens = direct.showbase.ShowBase.PerspectiveLens(170, 170)
slnp = self.render.attachNewNode(slight)
slnp.setPos(0, 0, 7)
slnp.lookAt(0, 0, 0)

If I run the code above, I have the following result with glitches in the shadows:


If it helps, if I change the PerspectiveLens parameters as follows:

lens = direct.showbase.ShowBase.PerspectiveLens(180, 180)

I have no shadows, no glitches but the following warnings:

:linmath(warning): Tried to invert singular LMatrix4.
:linmath(warning): Tried to invert singular LMatrix4.

Do you know what causes these glitches and how to fix them?
I tried everything I possibly could but I don’t get what is happening.

Thanks for your help! :pray:

That looks like an issue called “shadow acne”–I think that there have been a few posts about it on the forums, so I’d suggest searching for that term.

In the meanwhile, is your model perhaps two-sided–either by virtue of having applied the relevant setting (in Panda or in your 3D modelling program), or simply by virtue of having geometry modelled on both the top- and under- sides?

You see, shadows are generated by comparing depth-values–which in this case correspond to distances to the light.

Specifically, the comparison is between a given point on the surface in question and the distance recorded for the corresponding point in the shadow. If the surface-point is nearer to the light, then it’s not in shadow: whatever cast the shadow was further away. If the surface-point is further, then it is in shadow: whatever cast the shadow was nearer to the light, and so its shadow falls on the surface.

But if the surface that cast the shadow is pretty much at the same distance as the surface that is receiving the shadow, then imprecisions in the measurement of that distance–that depth–result in some parts being shadowed and some not being–which appears to be what we’re seeing here.

Now, there are a few things that might be done about this. Offhand:

One thing is to record shadow-distances for back-faces, rather than the front-faces used for usual rendering. Those tend to be a bit further away within a given object, and so the front-faces shouldn’t evince shadow-acne.

And another thing is to offset the distance for either the shadow or the surface, via a depth-bias. This can work–but can also result in another artefact in which the shadow appears a little too far from the object, making the object appear to float.

1 Like

Many thanks for your reply :pray: It’s always very interesting!

I did further testing: removal of normal maps, change of texture, separating ground mesh in two parts, …

Conclusion is : if I use a simple Blender plane I don’t have any shadow acne but as soon as I apply a BSDF texture (even a simple color) to this same plane, the shadow acne is back…

So I need to figure out which parameter in Blender I need to change to have a nice and clean result! :smile:

If anybody have some information on this, don’t hesitate! :wink:

As one of the solutions, check this box.


Checking this option indeed fixed the problem! :wink:
This is exactly what I was looking for, thank you for your help! :pray:

I am going to update the title of this thread to be more clear, it could help others!

1 Like