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.

Question Scale dithering with render target resolution

Discussion in 'Shader Graph' started by WayNexus, Nov 29, 2022.

  1. WayNexus

    WayNexus

    Joined:
    Nov 19, 2020
    Posts:
    3
    I have a basic xray shader that uses the Dither node, and I'd like it to not scale with the render target resolution (i.e. when Render Scale changes in the URP asset).

    Is there a way to get the dithering to always appear like render scale = 1 below?

    Render scale = 1
    Screenshot 2022-11-29 at 11.34.58 AM.png

    Render scale = 0.8
    Screenshot 2022-11-29 at 11.35.06 AM.png

    Render scale = 0.6
    Screenshot 2022-11-29 at 11.35.14 AM.png


    Render scale = 0.5
    Screenshot 2022-11-29 at 11.35.36 AM.png
     
    Noogy likes this.
  2. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    122
    I'm running into this exact same issue with shadergraph dithering and renderscale. I've noticed some 3rd party custom shaders also exhibit the same issue, but others (like Stylized Grass Shader) seem to accommodate for the renderscale dither fine.

    I'd love to also fix this issue in my shadergraph shaders, since I'm dynamically adjusting renderscale for increased performance.
     
  3. JAT25

    JAT25

    Joined:
    Sep 19, 2018
    Posts:
    2
    Had this exact issue today. To solve it I just added a "Screen Position" node, attatched to a "Tiling and Offset" node, and then set tiling via code to match render scale, then attatched it to "Screen position" slot in "Dither" Node.

    upload_2022-12-12_15-51-39.png

    At least this worked for me.
     
    Noogy likes this.
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    289
    If anyone is interested in calculating the URP Render Scale in shader (graph), you can try:

    Code (CSharp):
    1. // Half precision should be enough for Render Scale.
    2. // "_ScreenSize" and "_ScreenParams" are global variables.
    3. half2 renderScale = _ScreenSize.xy / _ScreenParams.xy;
    Not sure whether this is the best way because I remember that there're other ways to access it. (seems to be zw of a vector4)

    For example, the URP Render Scale is set to 0.5 in the picture below.
    Shader_RenderScale.jpg
     
    Noogy likes this.
  5. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    122
    Thank you both so much, I went with the solution in @JAT25's post. Plugged in a float into the Tiling and Offset tiling tab and then calling Shader.SetGlobalFloat("_renderScaleTiling", urpPipeline.renderScale) in my script. A tad shimmery but leagues better than the effect I was getting before.
     
  6. JAT25

    JAT25

    Joined:
    Sep 19, 2018
    Posts:
    2
    Thanks @wwWwwwW1 That code is better than using an external script. For the rest who dont know how to implement the custom function my final solution was this:

    upload_2022-12-13_8-59-27.png
     
    wwWwwwW1 likes this.
  7. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    122
    I'd be interested in trying it this way since feeding a vector2 instead of a float might be more accurate and help with the shimmering.

    However, I might be doing something wrong with the custom function. (_ScreenSize.xy / _ScreenParams.xy) always returns 1 for me regardless of my renderscale?
     
    Last edited: Dec 13, 2022