Overlay flat shapes


I ran into the problem of how to display multiple (dynamically created) overlaying flat shapes without getting artifacts.


Both elements are created like in the documentation and are positioned in the exact same horizontal layer (same height coordinates, same orientation, different sizes).

Is there a simple method to decide, that one of those elements is supposed to overlay the other? Do I have to use Bitmasks? Thanks in advance to everyone that gives even the smallest hint of how to solve this!


You could put them into the “fixed” culling-bin, and differentiate them via bin sorting-order. (You may find that disabling depth -writing and/or -testing is called for in addition, to prevent z-fighting.)

See this page for more information.

Perfect, this was exactly what I needed. Unfortunately, this topic did not catch my eye when I looked through the documentation.

Thank you so much, @Thaumaturge!

1 Like

The hint provided by Thaumaturge works for the most part.

I set two flat (and very large/long) surfaces (ground: created with cardmaker + roads: multiple quite long manually created geom) that are supposed to be displayed behind the third surface (road markings) at any time to be in the background-bin. This works well for most cases but sometimes it results in weird visualization, when some other objects “sink” into the ground and should not be displayed in front of the floor.

As far as I understood the documentation about this topic, you can not make panda3d to always render one specific geom behind another specific one without affecting other objects as well. Is that right?

1 Like

It’s not impossible, but it’s tricky. There was another thread on this recently, I believe–I think that it might have been this one; perhaps you’ll find some answers there.

However, I suspect that there may be a simpler solution available in your case.

Hmm… Given what you describe, perhaps it might work better to re-enable depth -writing/-testing if you’ve disabled it, and to instead use a depth offset to prevent the depth-fighting that seems to have been the original problem. (Along with using culling bins to enforce rendering order, as mentioned previously.)

This can be done by calling “setDepthOffset(<some value>)” (see the API here) on the object that should render in front of the other. The value of “<some value>” is an integer; experiment to see what sort of value works for your scene, starting with a value of 1.

1 Like

Well, that was easy! setDepthOffset worked perfectly. I should probably work my way through all the NodePath-functions before I ask a question next time.

Thank you so much again @Thaumaturge! Thanks also for the recommendation of the other thread. It doesn’t have to be that complicated in my case though, I think.

1 Like

Honestly, there are so many methods within the NodePath class that I wouldn’t expect someone to go through all of them at once!

Either way, I’m glad that this approach seems to have worked out for you. :slight_smile: