Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Custom shaders not working in 2021.3 LTS

Discussion in 'Universal Render Pipeline' started by markus_unity31, Mar 24, 2023.

  1. markus_unity31

    markus_unity31

    Joined:
    Nov 9, 2021
    Posts:
    1
    Hi,

    I've had issues with invisible objects using the custom shader template from:
    https://docs.unity3d.com/Packages/c...riting-shaders-urp-basic-unlit-structure.html

    I initially noticed it in a project using 2021.3.19f1, but I downloaded the latest (2021.3.21f as of today) and created a new project with the 3D URP template and got the same problem. It does work with 2022.2.8f1 using:
    https://docs.unity3d.com/Packages/c...riting-shaders-urp-basic-unlit-structure.html

    The object does not render at all when opaque, but works fine when changed to transparent (whenever render queue over 2500).

    Can anyone confirm or is it just me?
     
  2. AbelChiu

    AbelChiu

    Joined:
    Nov 29, 2016
    Posts:
    12
    I have the same problem, switching to the Android platform also worked
     
  3. reddo

    reddo

    Joined:
    Jul 1, 2015
    Posts:
    36
    Same problem here as stated above when switching a project from Android to PC using 2021.3.21f.
    Also tested a fresh 3D URP project on 2021.3.23f. On PC platform, for example, a cube with Unlit/Texture shader is invisible, but when switching to Android it renders ok.
     
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    495
    Hi, if the shader works well when changed to transparent or switching the build target to Android, I think it's because the shader doesn't have a DepthOnly pass (or DepthNormals pass when SSAO is set to normals mode).

    URP sets the Depth Priming to "Auto" by default, which will always be disabled on mobile devices. Depth Priming (Depth Prepass) is an overdraw optimization technique, and it requires a depth pass in your shader.

    You can either disable Depth Priming or add a DepthOnly pass to the shader. You don't need to output the depth in the fragment shader, just copy the Unlit pass and add
    "LightMode" = "DepthOnly"
    to the tags.

    For example:
    Code (CSharp):
    1. Pass
    2. {
    3.     Name "DepthOnly"
    4.     Tags
    5.     {
    6.         "LightMode" = "DepthOnly"
    7.     }
    8.     // ...
    9. }
     
  5. reddo

    reddo

    Joined:
    Jul 1, 2015
    Posts:
    36
    @wwWwwwW1, thanks very much for the pointer. That fixed it.
     
    wwWwwwW1 likes this.