0
Follow
0
View

How does Unity SpriteRender's sheder fix the default rendering pipeline overlap after translucent rendering?

a58438331 注册会员
2023-02-27 15:43

To resolve the default rendering pipeline after translucent rendering overlap, you can use depth test and depth write to solve the problem. Specifically, you can add the following code to the shader:


Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
Pass
{
    ZWrite Off // 禁止写入深度缓冲
    Blend SrcAlpha OneMinusSrcAlpha // 使用透明混合
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // 省略其他代码
    ENDCG
}

This ensures that when drawing a translucent object, only pixels closer to the camera will be drawn, thus avoiding overlapping problems. Also, since depth writing is disabled, such a translucent object does not affect the depth information of subsequent objects, thus avoiding the depth collision problem.

About the Author

Question Info

Publish Time
2023-02-27 15:43
Update Time
2023-02-27 15:43