Hi,
I have another webgl renderer on my canvas (maplibre) that is setting the depth buffer. afterwards I render babylonjs on top. However this leads to some z-fighting and I am wondering if I can avoid it by setting some kind of global zOffset on the depth buffer before rendering with babylonjs.
I found engine.depthCullingState.zOffset, but this has no effect.
Moving the babylon camera a bit back helps, but I would still prefer a better way.
Maybe @Evgeni_Popov knows this?
We don’t have such function, but you can do something like this (line 2-5):
Thanks for the reply!
I don’t think that setting zOffset will move the depth buffer by a certain value. It does not have an effect on my z-fighting issue.
Is there any way I could access the depth buffer and move try to increase it?
Not sure if it is a good idea though…
zOffset
is meant to fix z-fighting issues. Try smaller values than -10 (-100 / -1000). You can also try to override engine.setZOffsetUnits
. See glPolygonOffset for more information about zOffset
/ zOffsetUnits
(the former corresponds to factor
in this doc, and the latter to units
). I don’t think you can access the depth buffer, as maplibre probably renders directly to the canvas, so the depth is a framebuffer and not a texture.
Hm seems like I have to stick to moving the camera or its perspective matrix then.
The zOffsetUnits work well on materials, I can see how their meshes move away from the map. But if I do it globally there is no effect.
Thanks though!