Patterns appearing while enabling shader

Hi, I am learning Panda3d and was trying to render a model with shadows. So I added a directional light, setup lens and frustum and enabled shader. However, although it created the shadows, but there are strange black circular patterns everywhere. Here is my code and a snapshot of the output

class MyApp(ShowBase):
    def __init__(self):

        props = WindowProperties()
        self.scene = self.loader.loadModel("Bar_1.dae")
        self.scene.setPos(0, 0, 0)

        # Adding a directional light
        dLight = DirectionalLight("dLight")
        dLight.setColor((1.0, 1.0, 1.0, 4))
        dLight_node = self.render.attachNewNode(dLight)
        dLight_node.setPos(30, 20, -5)
        dLight_node.lookAt(0, 0, 0)

        # Setting up lens nd frustum.
        dLight.getLens().setNearFar(10, 50)
        dLight.getLens().setFilmSize(20, 20)
        dLight.setShadowCaster(True, 4096, 4096)

        # Enable shader.

app = MyApp()

However, with render.setShaderAuto() disabled there is no such patterns but obviously no shadows. I have tried with different buffer and film sizes. But every time those patterns reappearing. I have tried the same code with an egg file (although not the same environment). In that case. no problem at all for creating shadows.

What is the reason for this.
Thanks in advance.

This is known as shadow acne or self-shadowing artifacts. The problem is probably that the model has double-sided surfaces. Normally, Panda enables backface culling, so it should not be an issue for single-sided surfaces.

Thanks rdb. I googled about it and to some extent understood the problem. It seems like I need to adjust the bias of the shader. Is that a correct understanding? How do I set the bias?

Thanks in advance.

Ohh…got it.

self.render.setDepthOffset(-2) did the trick.


A quick caveat: If, as rdb suggested, your model has double-sided surfaces, then be aware that rendering it may not be as efficient as it could otherwise be: the renderer might not be able to cull away quite as many polygons as it otherwise might.

(The renderer generally culls away surfaces that face away from the camera (i.e. “backfaces”), thus reducing the number of polygons to be processed, I believe.)

That said, your scene looks fairly simple; if the above is all of it, then the impact may not be all that great. Still, it may be something to be aware of in general!

Thanks for the tip. Indeed, when I was exporting the scene as a collada file from google sketchUp, the ‘double sided’ option was checked. After rdb’s suggestion, I unchecked the option and exported again. This is also required as I need to write a collision checker which does a lot of culling operations.

Thanks again.

1 Like