Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Resolved URP Transparency with multi pass has blending issues

Discussion in 'Shaders' started by Buttermilch, May 5, 2024.

  1. Buttermilch

    Buttermilch

    Joined:
    Nov 23, 2016
    Posts:
    38
    What I want to achieve: I have two meshes inside of each other. The one on the inside shall fade out when you're to close to it.

    I've already got the shader running partially.
    The shader for the inside mesh contains two passes. First one renders an outline by culling front faces and slightly expanding the mesh along its normals. The second one renders just a color.

    The problem:
    Here's a screenshot of one part of the mesh which works as expected:
    upload_2024-5-5_11-20-52.png
    Now here's another part of the mesh where the shader does not work correctly any more (it's transparent but somehow not blending correctly):
    upload_2024-5-5_11-22-4.png

    Also another thing I couldn't figure out: The "Outline" pass does not work when I remove the tags or change them to be transparent.

    My shader setup looks like this:


    Code (CSharp):
    1.  
    2.  SubShader
    3.     {
    4.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    5.         ZWrite On
    6.         Blend SrcAlpha OneMinusSrcAlpha
    7.         LOD 100
    8.  
    9.  
    10.         Pass
    11.         {
    12.             Name "Outline"
    13.             Tags {
    14.                 "RenderType"="Opaque"
    15.                 "RenderPipeline"="UniversalPipeline"
    16.                 "LightMode"="UniversalForward"
    17.  
    18.              //... rest of code
    19.           }
    20.           Cull Front
    21.  
    22.  
    23.         Pass
    24.         {
    25.             Name "Toon"
    26.              //... rest of code
    27.          }
    28.  
    29.          Fallback "VertexLix"
    30.  
    31.  
    In both passes I use this code inside the vertex shader to determine the vertex world position:
    Code (CSharp):
    1. o.worldPosition = mul(unity_ObjectToWorld, v.vertex);
    Then I use this code in both passes for the fragment shader alpha color:
    Code (CSharp):
    1. float offset = (_camDistOffset / 1000.);
    2. float distToCam = distance(i.worldPosition, _WorldSpaceCameraPos) * offset;
    3. float alpha = saturate(1. - 1. / distToCam);
    4. return float4(color.r, color.g, color.b, alpha);
    5.  
     

    Attached Files:

  2. Buttermilch

    Buttermilch

    Joined:
    Nov 23, 2016
    Posts:
    38
    Update: apparently setting the render queue for both passes to Overlay solved the issue. I have no idea why though.