Search Unity

Sprite renderer material with addative/subtractive color?

Discussion in 'General Graphics' started by Marscaleb, Oct 5, 2019.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    A feature I want within my game is to change the color mode for sprite renderers.
    By default, the color is multiplied to a sprite's texture. A color of white (1,1,1) makes the sprite appear normal, and a color of black (0,0,0) makes the sprite turn black. But I'd like to be able to make a sprite turn a solid white, or another solid color. If I could change the color mode to add or subtract this would be a simple matter.
    But there is no such option in the sprite renderer.

    Except that there IS a property for the sprites "material." So I'm wondering if it would be possible swap out the default sprite material for an identical material but that applies the "color" property in a different manner.

    But I have no experience working with materials and shaders in Unity, and furthermore I can't even find the default sprite material to even try to look at it to see if I could alter it.
    Could someone give me some help here? How could I add a new sprite material to my game that operates the way I described?
     
  2. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    Okay then, can someone at least tell me where I can actually find the default sprite material? Because when I try to select it it sends me to the root assets folder but I don't see it there.
     
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,638
    Unity shaders are precompiled. The source for the Unity's included shaders is a available as a separate download.

    https://unity3d.com/get-unity/download/archive

    Go to your Unity version in the list. In the dropdown where it says "Downloads (Win)" one of the options should be for "Built in shaders"
     
  4. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    this is easy, but not exactly simple in terms of learning the ins-n-outs, but you use the SRP and author it in the shadergraph

    making assumptions (...what i think you will want and is simple to comprehend for many)

    • a color node RGBA to LERP as an overwrite
    • (color.a * texture.a) to preserve your shape
    • slider as your vec1 to slide through 0-100%
    • vertex.RGBA mult

    upload_2019-10-9_6-56-25.png
    this works - tested on shuriken with sprite
    spriteLERPy.gif
    (Premultiplied-alpha blending)

    your color swatch can be altered during runtime.. but the LERP overtakes particles simultaneously rather than over their life, (for that you could to pass the slider as vec1 into custom.x vertex stream)

    attach the parent texture to the material and assign the sprites in the texture module, not sure if you can attach a texturePack atlas to the material as IIRC that packer is now legacy*

    if you want to use the (experimental) Sprite Unlit MasterNode
    upload_2019-10-9_7-0-14.png
    note : it only has 1 blend mode at the moment (srcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha), and no way to override vertex.RGBA in particles since it ignores the vertexColor node

    and if you're dead set on add/subtract tint i.e. offset (it's non-proportional rather than multiplicative 'fade' so typically unexpected/undesirable by most people) but you'd add the color swatch but remapped -1..1, very easy in the graphing
    texture.RGBA += 2*color.RGBA - 1
    you prob want to clamp/saturate that output before going to vertex to prevent outside of 0..1 bounds
     
    Last edited: Oct 9, 2019