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.
  2. Dismiss Notice

Bug Shader.maximumGlobalLOD no longer works?

Discussion in 'Universal Render Pipeline' started by thebarryman, Apr 27, 2023.

  1. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    122
    I've been trying to debug why Shader.maximumGlobalLOD is no longer working in Unity 2021.

    I have my shader set up like so ..

    SubShader
    {
    Name "Fancy"
    LOD 500
    }
    SubShader
    {
    Name "Simple"
    LOD 100
    }

    But no matter what I set Shader.maximumGlobalLOD to, the "Fancy" subshader is always used. As far as I can tell, the Shader.maximumGlobalLOD property no longer does anything?

    Previously, I have been successful using this pattern. My understanding is the compiler is supposed to step through the subshaders from top to bottom and use the first one that it finds which is valid.
     
  2. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    122
    Upon further investigation, this appears to be a bug that is unique to the Unity project I am working in. However, there doesn't appear to be any code modifying Shader.maximumGlobalLOD other than my test script, and yet the maximum LOD subshader is always selected during rendering. Is there a way to debug Unity's subshader selection process?
     
    Last edited: Apr 27, 2023
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,844
    I don't think there is. Did you try setting the LOD on the shader directly?
     
    thebarryman likes this.
  4. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    122
    Yes, I did try that route as well with no success. Purely a guess but maybe some plugin in the project (Oculus?) is changing the subshader selection process in some way?
     
  5. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,844
    Plugins can normally only affect it using the public API as well.
    You could try to do it the hard way - move the subshader with the lower LOD to a different shader and juggle the shaders/materials at runtime...
    Also, maybe tags are preventing it from being selected?
     
  6. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    122
    I don't believe the tags are a problem, I have tried the same simple test shader in an empty project created with the URP template which shows the LODs are being selected correctly, but in the actual project that test shader's SubShader selection process was broken.

    Here are the tags in the actual SubShader I am trying to use -

    Tags {"RenderPipeline" = "UniversalRenderPipeline" "Queue" = "Geometry+100" "RenderType" = "Opaque" "IgnoreProjector" = "True"}

    And in the constituent passes ..

    Tags {"LightMode" = "UniversalForward"}
    Tags { "LightMode" = "ShadowCaster" }
    Tags { "LightMode" = "DepthOnly" }
     
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,844
    Would it be possible for you to submit a bug report with the project where the issue exists?
    We could then try to figure out what the issue is.
     
  8. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    122
    Unfortunately for legal reasons I don't have the ability to share the project. I would submit a minimal repro but I'd probably have to solve the issue myself first!