Shader graph and SpriteRenderer / Image color?

From a SpriteRenderer or Image component, how do you set the main color of a shader made in Shader Graph?

I’ve written a very simple test shader (which you can see below), with a color property whose name and reference value are set to “_Color”. Yet, as you can see in the picture below, when I change the color value of a SpriteRenderer or Image component, the value isn’t changed. I’ve also tried “_BaseColor”, but this doesn’t work either.

I was thinking that it perhaps has something to do with a missing [PerRendererData] flag in the compiled shader, but I haven’t been able to find a way to mark a shader property that way in Shader Graph.

Does anyone know how to solve this issue? I feel like I’m missing something obvious, but I’m kinda stumped regardless.



Whoops, nevermind. I figured out.

For anyone else having the same issue, setting the material type to “Sprite Unlit” resolved the issue for me. Not sure what this option changes behind the scenes, but hey it works, I’ll take it.

2 Likes

Sprite renderer changes the vertex color of the mesh so try multiplying by that in the shader graph. (I read about this somewhere not sure though)

1 Like

having an exact same issue, but setting material type to Sprite Unlit doesn’t help… any help?9556756--1350994--upload_2024-1-2_3-9-44.png

Turns out sprite unlit multiplies the result with the color automatically without sending the color to the shader… oops

EDIT: somewhat fixed this by writing a script to manually send the image color every frame

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode]
public class sendVertexColorToShaderGraph : MonoBehaviour
{
 
    Image _image;
    Material _mat;

    void Start()
    {
        _image = GetComponent<Image>();
        if(_image.material != null)
            _mat = _image.material;
    }

    void Update()
    {
        if(_mat != null)
            _mat.SetColor("_Color",_image.color);
    }
}