starting with 2023.3.0a10, Sprite and Canvas sub-targets feature a Disable Color Tint option.
This allows you to control how you want to use the Sprite or UI Element’s color in your Shader Graphs.
Note: this color transits through Vertex Color.
Here’s an example of a Canvas Shader Graph, with Color Tint disabled, multiplying the Main Texture by Vertex Color, resulting in the same output, but with more flexibility to tint only portions of the output.
Vertex Colors are used in the Editor, but at Runtime the Sprite Renderer’s color comes through the unity_SpriteColor property.
So using a Custom Function Node with the following code, will provide the Runtime color, which can be multiplied by the Vertex Color for Edit mode.
Hi @Skjalg ,
first of all, I see that you’re making a Shader for UI Canvas, so you don’t need the SpriteColor/SpriteData mentioned above, that’s only for Sprite Renderers.
All you need is to multiply by the Vertex Colors.
If the Project’s Color Space is set to Gamma in Player Settings (Project Settings), everything will just work with no conversion required, as the Vertex Colors and rendering will be in the same color space.
If set to Linear, Vertex Colors will be in Linear space, so everything works the same.
Unless the option “Vertex Colors Always In Gamma Color Space” is enabled in the Canvas component.
In which case, Vertex Colors will be in Gamma space and require conversion to Linear space. That’s something you can do with a Colorspace Conversion Node.
Now, if you want to make your Graph properly handle color spaces, you can also use a Custom Function Node with the following code:
I can accurately reproduce the regular image canvas colors with that shader layout you made. It tripped me up a bit that I had to make the linear conversion shader a file and that a file works differently than pasting in the code, so I’m leaving that here for future me to read
However, and this is probably due to me being a beginner here, but I am still not getting my shader to work correctly. I am just trying to multiply the colors to create an overbright effect and when i set multiply to 2 and all the colors to 0.5 it appears darker than it should. I have two Image’s in the scene view displayed. The bottom one is no material (so how it should look regularily). The top one is using this shader graph that has a simple multiply at the end. In my head, when the colo
FYI, from Unity 6000.0.0b16 and above, the Vertex Color will always return the Sprite Renderer’s Color, both in Edit Mode and at Runtime.
This shall make it a lot easier to work with it.
@FredMoreau is it possible to get the tint color from SpriteRenderer in the URP Lit shader (non-sprite version)? I’m able to get it from Vertex Color node with “Sprite Lit” material, but not with the regular Lit shader.
I’m working on a game where I need sprites in 3D world interacting with 3D lights and casting shadows. Everything works with the regular URP Lit shader, except for the tint.
Jumping in to say I have the same need, and Vertex Color does not get the color when using the Lit material. However, the custom function provided by Fred on Jan 17 still works (haven’t tested in build yet!). Thank you, the info here has been very helpful, I lost a couple of hours trying to figure out how to pass color information from the sprite renderer with shader graph but all works now
Blockquote
Was there a reason not to use Sprite Lit ?
In my case, I’m using sprites in a 3D world. I like that I can use 9-slices to create various layouts on our “3D UIs” or decals. However, Sprite Lit does not seem to work with 3D lights and APVs in URP, so I needed to use the URP Lit Shader. Sprite sorting is not so important for my use case.