If I’m writing a normal shader, I can get at a SpriteRenderer’s .color by reading the the vertex color. I also have full control of the final, output color.
When I’m creating a shader in ShaderGraph using the SpriteLit template, I can still read the .color through reading the vertex color. But I can’t do anything about the color being automatically applied to the final output color.
That’s a problem! I need to create an effect that first applies the SpriteRenderer’s color to the texture, and then applies the rest of the shader effect. That’s trivial in a normal shader, but in the SpriteLit template, I’m unable to prevent the tint being applied in the end.
Any way I can fix this now, that’s not a huge hack? I’ve gotten some suggestions, but it seems a bit over the board.
This would be extremely useful. If there were Lit and Unlit master nodes which left it to the user to apply vertex color earlier if at all, I’d immediately switch to them in nearly all cases.
This so much. Could someone elaborate what’s happening behind the scenes? I’m just confused as to how shadergraph seems to behave differently with sprite renderer colors. I don’t even see this issue happening on UI Image components.
I asked someone on the Unity Discord, and they pointed me to some source code. Unity’s shader graph to shader conversion code seems to have hard-coded “multiply the vertex color in after the shader graph”.
We ended up just copying the Sprite-Lit’s code and making a few adjustments as necessary. Took a lot less work than the shader graph version did.
I still find it weird that they forcibly apply the color after your graph, because of two reasons:
The node “Fragment > Base Color” implies a final shader output
The vertex color (which the sprite renderer sets) is available for use within shader graph, so that’s where I would expect the operation to take place.
For now I’ll be ‘pre-dividing’ my output as a before-last step in shader graph, hoping that this will be an optional setting in the future.
@Waarten do you mind specifying which version of URP you ran on this project?
I’m currently having the same issue, and have tried multiple versions of both Unity & URP, to no avail.
In case someone lands on this thread looking for an answer to this question.
We’ve added the ability to ‘opt out’ of final tint in both Canvas and Sprite Targets as of 2023.3 / Unity 6.