- Home /
Front of mesh is more transparent than back of mesh
I'm making a simple third person camera system, and I have it so when the camera gets close to the player mesh it becomes more and more transparent. However, it seems that the mesh doesn't become equally transparent all around, rather the front of the mesh is more transparent than the rest. This makes for a slightly jarring transition when switching from an opaque rendering mode to a transparent rendering mode. How can I make the transparent object equally transparent across the whole mesh so it can be a smooth transition?
This is what the start of the transition looks like.
I think transparency is because of the overlap of your objects. As much as I know there is no way of doing that.
Answer by Pangamini · Sep 05, 2021 at 08:31 PM
Transparent objects are tricky. For example, ovelapping surfaces have to be sorted from back to front in order to render properly (with a few exceptions). Unity does that on the renderer level, however it won't sort individual triangles. There are few things that could be considered in general:
Split your mesh to several smaller, ideally convex meshes. That way unity can sort them, but the rendering becomes less efficient. For a small scene, this wouldn't be a big problem though.
Use some commutative blending mode. See, the problem with ordering is that the result depends on the order in which objects are rendered, as they overlap. It's the same as if you were to change the order of math operations in an equation. In some few cases, the order doesn't matter. For example, multiplication or addition. Unfortunately, there is no way how to smoothly turn an opaque object into a transparent one like that.
Probably what you will end up doing: Depth pre-pass. The trick is to make sure that the triangles you are rendering don't get rendered out of order. Since unity won't sort the triangles in a mesh, what you can do is to prevent them from being rendered. Your transparent material most likely has depth-write turned off (to avoid even worse results than what you have now). The trick is to render the mesh, but only writing to the depth buffer but not color. So nothing actually gets drawn. After, you render your transparent mesh with default depth test. In the final image, you will only see the closest surface of the transparent object, but you won't see itself through itself.
Order independent transparency. I don't know much about this topic though, so I will leave it for you to study on your own