Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shader/Material Priority and RenderQueue for transparent materials

Discussion in 'Universal Render Pipeline' started by AzurySimon, Feb 11, 2020.

  1. AzurySimon

    AzurySimon

    Joined:
    Jul 16, 2018
    Posts:
    38
    After creating a world space UI in my application I noticed that all of the other transparent materials using URP shaders get drawn on top of it. I was able to fix this by setting those shaders' priority to 50 via the inspector, but i wondered why this happens.

    After a bit of digging I found that changing the priority basically changes the materials renderQueue property, but it does not do so by simply taking the default value (e.g. 3000 for transparent shaders) and subtracting the priority as an offset (so a priority of 50 would result in a renderQueue = 2950, -50 would result in 3050). Instead it adds 50 on top of it, resulting in renderQueue values ranging from 3000 to 3100.
    The code for that priority to renderQueue calculation can be found here:
    https://github.com/Unity-Technologi...versal/Editor/ShaderGUI/BaseShaderGUI.cs#L425

    Since the default value for priority is 0, the default renderQueue for transparent materials is 3050. So to make every other shader out there not currently supporting this Priority system work with this would mean to either change those shaders' renderQueue to 3050 or to set every transparent URP materials priority to 50.

    In my case I would have to use the default UI shader/material, change its renderQueue and assign that material to every UI element I have (or change the priority of every transparent URP material).

    Is this the intended behaviour?

    It certainly "breaks" world space UI, since the default renderQueue for that material is still 3000.
     
  2. Codexus

    Codexus

    Joined:
    Dec 19, 2009
    Posts:
    5
    Crazy stuff. I just wasted over an hour trying to figure out why my custom ShaderGraph transparent material was not displayed correctly (it defaults to priority 3000) and only found your post once I understood what was going on by including "3050" in my google search.

    It has to be a bug, it can't be a coincidence that the UI allows to set priorities from -50 to 50 and ends up being off by 50 from what we would expect.
     
  3. Codexus

    Codexus

    Joined:
    Dec 19, 2009
    Posts:
    5
  4. AzurySimon

    AzurySimon

    Joined:
    Jul 16, 2018
    Posts:
    38
    Thanks for your feedback, Codexus! Good to know this is being addressed. I am still a bit surprised this is not a problem more developers seem to be having, considering the lack of responses and/or similar threads so far.
     
  5. AzurySimon

    AzurySimon

    Joined:
    Jul 16, 2018
    Posts:
    38
    According to the changelog this was fixed in URP 7.4.0.
     
    FracEdd likes this.