Model transparency glitchy

Hello,

I have a model that has been exported from blender. The materials have a diffuse color and transparency.

This model is of a glass pipe with water in it.

When I use this model in the roaming ralph example, I notice that the portion of the water that is inside of the pipe is incredibly glitchy. at some camera angle it disappears and one can only see the pipe itself. (see screenshots)

The model itself is also attached.

Am I doing something obviously wrong?

Thank you.

pipe.egg (207.2 KB)

Transparency can be a tricky thing, I fear. In short, and somewhat roughly:

In order for semi-transparent objects to be rendered correctly, they’re generally rendered from furthest to closest, allowing them to overlay each other as expected. However, sorting each individual polygon might be performance-intensive, I think, so instead we simply sort the objects.

But with largish objects, or objects that overlap in awkward ways, which has its origin closest to the camera might change depending on where the camera is. This, I think, may be why your water flickers so: from some positions the water’s origin is further from the camera than the pipe’s, resulting in it being rendered first, and so being visible; from others, the pipe’s origin is further away than the water’s, resulting in it being rendered first, and the water being missed.

The Panda manual gives a more-detailed discussion of this on the following page, I think: https://www.panda3d.org/manual/?title=Transparency_and_Blending

There are a few potential options, at least some of which the above-linked page discusses, I believe.

In your case, as long as the water is never intended to surround the pipe or otherwise cover it, you might get away with simply forcing Panda to render the water first, and then the pipe. This can be done by putting the objects into appropriate culling-bins (or a single bin with a fixed render-order). More information on doing this should be found on the following page, I believe:
https://www.panda3d.org/manual/?title=How_to_Control_Render_Order

Note that with this approach, you’ll likely not see the pipe when looking through the water.

1 Like

Thanks for the great advice! One more thing though.

This is slightly off topic but if you notice in the screenshots, the pipe looks significantly brighter in some spots. This is because I used a Directional Light. I would prefer to avoid this to get a “flatter”, more even look. First thing that came to mind is Ambient Light, but after reading up on it and trying it out it just makes everything its color, as expected from the various explanations I read. What would be a good way to provide nice, even lighting all around the model with minimal change to the colors (shouldn’t be too bright).

Thanks.

Panda3D defaults to per-vertex lighting, which isn’t as smooth as per-pixel lighting. To enable per-pixel lighting you can either write custom shaders or enable Panda3D’s auto-shader. You can enable the auto-shader with base.render.setShaderAuto().

Sorry for the misunderstanding. What I meant by smoother is to make it not look like there is a specific light source. In other words, to provide an even lighting.

[moving this question to its own discussion]