2023.3 Disable Color Tint for Sprite & Canvas Targets

Hi,

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.

10 Likes

Very nice. Any prospect for this being backported?

3 Likes

This feature is bugged. As soon as you press play, vertex color will be white. (Tested in 2023.3.0a18, URP)

Hi @Nit_Ram ,
Thanks for your feedback. This is with Sprite right?

FYI,
Sprite Renderers don’t just use Vertex Colors to pass their color to the Shader.
The devs are looking into it.
I’ll keep you posted.
Thanks!

Okay, here’s the solution.

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.

#ifdef UNIVERSAL_SHADER_VARIABLES_INCLUDED
SpriteColor = unity_SpriteColor;
SpriteProps = unity_SpriteProps;
#else
SpriteColor = float4(1,1,1,1);
SpriteProps = float4(0,0,0,0);
#endif

SpriteProps holds flipX and flipY in the x and y.

We shall document this, and certainly provide it as a Sub Graph in a Samples later.
Thanks for the feedback.

4 Likes

Am I doing something wrong then, because I can’t get this to work correctly. I’m using 2023.3.0b4 with Shader Graph 17.0.2.

Here’s the same graph you have displayed on the left and a regular sprite on the right. Why aren’t they the same?

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.

But… to your point, Vertex Colors in Canvas, can be in Gamma Space or Linear Space.

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.
9624506--1366688--upload_2024-2-5_10-8-31.png

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:

#ifndef UI_COLOR_SPACE_CFN
#define UI_COLOR_SPACE_CFN

int _UIVertexColorAlwaysGammaSpace;

void IsLinearSpaceConversionRequired_float(out bool linearSpaceConversionRequired)
{
    if (_UIVertexColorAlwaysGammaSpace && !IsGammaSpace())
        linearSpaceConversionRequired = true;
    else
        linearSpaceConversionRequired = false;
}
#endif

This will return true when you need to apply conversion. The graph will look like this:
9624506--1366775--upload_2024-2-5_10-33-22.png

Hope this helps.

1 Like

Yes that’s very helpful. Thank you!

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 :slight_smile:

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

1 Like

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.

Thanks for the feedback everyone!

3 Likes

And here it is!

9785244--1403832--upload_2024-4-22_6-20-50.png

I don’t see the disable color tint on sprite shaders in 2023.10f1 URP. Sprite lit/custom sprite lit also doesn’t have it

image

I really need this because I want to override the vertex color in runtime in a shader.

Its bugged unfortunately

So yes, that’s only available in Unity 6 (beta 16) and above.

The thread started at 2024.3.0a10 version so that made me think it’s gonna be in 2023.3.10f1.

@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.

Here’s my shader:

P.S. Thank you for all the information provided in the thread

2 Likes

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 :slight_smile:

1 Like

Thanks @rockin, @spaceapple,

I just gave this a try in Unity 6 (6000.0.20f) and it works.
Using the URP Lit Target.

Sprite Color Custom Function:

#ifdef UNIVERSAL_SHADER_VARIABLES_INCLUDED
SpriteColor = unity_SpriteColor;
SpriteProps = unity_SpriteProps;
#else
SpriteColor = float4(1,1,1,1);
SpriteProps = float4(0,0,0,0);
#endif

FlipUV Custom Function:

Out.x = Flip.x > 0.5 ? UV.x : 1 - UV.x;
Out.y = Flip.y > 0.5 ? UV.y : 1 - UV.y;

That said, Sprite sorting doesn’t seem to work properly with the URP Lit Shader.
Was there a reason not to use Sprite Lit ?

2 Likes

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.


image

1 Like