Search Unity

Question How to apply Sprite Renderer color value to URP shader?

Discussion in '2D' started by BasicallyGames, Jun 17, 2020.

  1. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
    I can't seem to figure this out. I have a sprite that's supposed to fade in by changing the sprite renderer's color value over time (Not the shader's color value) from completely transparent to completely opaque. This worked fine when I was using a standard sprite shader before switching over to the URP. Now that I've switched to the URP, I've created some custom shaders with Shader Graph. Now however, the sprite renderer's color value has no effect on the sprite. I'm guessing there's a way I can link the sprite renderer's color value to my sprite's shader in Shader Graph, but I can't figure out how. Anyone have any idea? Or is the color value on the sprite renderer obsolete with the URP?
     
  2. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
  3. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Within Shader Graph, name the color in its Reference field "_Color".
    The same rule applies for the main texture with "_MainTex".

    SG.PNG
     
  5. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
    Thanks, but that doesn't seem to be working. The sprite renderer's color value still has no effect.
     
  6. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Have you dragged and dropped the Color and are using it? If you change the default color for the Color input, does it change the output as anticipated? Perhaps the shader is not working right.

    Maybe you could take a screenshot of your shader graph.

    You might - I don't know if this is in fact a requirement - need to be using the 2D Shader Graph with 2D Renderer for it to work right, e.g. start from Lit2D / Unlit2D. I'm using that and it works.
     
  7. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
    Just coming back to say that changing the shader material from Unlit to Sprite Unlit was exactly what I needed. Thanks for the help!
     
  8. Ava42

    Ava42

    Joined:
    Aug 4, 2012
    Posts:
    33
    in ShaderGraph add new node search "color" and select "vertex color". from list.