[URP] Fix Transparent Mesh Rendering Order and Depth Artifacts
Solution
Unity 2021.x - Unity 6.3.x
Published Wed, Mar 25
Transparent meshes often exhibit flickering or incorrect layering because the rendering engine calculates depth based on the distance between the camera and the bounding box center of the object. This per-object sorting logic fails for complex or large meshes, particularly when using double-sided materials, leading to visual popping as the camera rotates.
Inconsistent transparency is caused by bounding box center sorting. Resolve this by adjusting material cull modes or splitting meshes into smaller segments for more granular depth calculation.
Visual popping and incorrect layering occur when the bounding box center of a mesh passes the calculated depth of another during camera movement. Unity sorts transparent objects from back-to-front based on these specific center points.
To resolve these sorting artifacts, follow these steps:
1.
Select your material in the Inspector and locate the Render Face or Cull Mode setting.
2.
Change this from Both to Front or Back to prevent the engine from sorting internal faces against external ones on the same object.
3.
For large or concave geometry, enable Depth Write on your transparent material. In the Universal Render Pipeline, this is located under Surface Options > Depth Write. Ensure Depth Priming Mode is enabled in your URP Asset to support this.
4.
Split your mesh into smaller sub-meshes within your modeling software. This creates multiple bounding box center points, allowing the engine to sort segments of the model more accurately relative to the camera distance.
5.
Navigate to Project Settings > Graphics and ensure the Transparency Sort Mode is set to Perspective for 3D environments.
Additional Tips:
- Use
Sorting Priorityon theMeshRendererto manually force specific objects to render above others regardless of their bounding box center. - Consider using
Alpha Clippingif the edges of your transparency do not require soft blending, as this allows the mesh to utilize the opaque Z-buffer for perfect depth sorting. - For intricate models like hair or foliage, a custom shader with a
Depth Prepasscan alleviate many sorting issues without splitting the mesh.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.