Search Unity

Sprite Shape Renderer color value

Discussion in 'Shaders' started by Glaswyll, Mar 25, 2020.

  1. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    103
    I'm using a custom sprite shader for our project. Sprite Renderer seems to work fine, and the color value gets passed to the material, but for some reason it can't see the color value for Sprite Shape Renderer.

    I temporarily changed the shader to just return the color value, and you can see the differences in these examples:

    Sprite Renderer:
    sprite-renderer-example.png

    Sprite Shape Renderer:
    sprite-shape-renderer-example.png

    As illustrated above, it works on sprites, but not with sprite shape. Not sure what's going on.

    The fragment struct I have is as follows:
    Code (CSharp):
    1. struct appdata {
    2.     float4 vertex : POSITION;
    3.     fixed4 color : COLOR;
    4.     float2 uv : TEXCOORD0;
    5.     float2 uv2 : TEXCOORD1;
    6.     float4 normal : NORMAL;
    7. };
    It seems to work with the Sprites - Default shader, so I'm not sure what I'm doing wrong.

    Thanks in advance
     
  2. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    103
    Of course I find the answer after asking the question. I didn't have _RendererColor defined or used in my shader.
     
  3. djidjo

    djidjo

    Joined:
    Jun 26, 2013
    Posts:
    2
    Hi Glaswyll, I have started using spriteshape for a new game and I really like the tool. However, when a custom shader is used, I have the same problem you got. How did you manage to make it work? what is _RendererColor that you used? By the way, my custom shader is build with Amplify shader. Thanks.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,341
    Unity's built in sprite renderer uses either the mesh's vertex colors, and/or a
    float4 _RendererColor;
    property to set the sprite's color. For the built in sprite renderer, vertex colors are used for batched sprites, and
    _RendererColor
    is used for instanced sprites. However the default sprite shader always applies both regardless.

    It seems SpriteShape uses only makes use of the
    _RendererColor
    property, leaving the vertex color unmodified.

    That means that to support SpriteShape compoents and Sprite Renderer components with a single ASE shader you'll want to add a color material property called
    _RendererColor
    and use that and the vertex color to multiply the texture.
     
    djidjo likes this.
  5. djidjo

    djidjo

    Joined:
    Jun 26, 2013
    Posts:
    2
    Thank you bgolus ! It worked like a charm! You saved my day!