Search Unity

Only yellow color shader

Discussion in 'Shaders' started by ggooxxoorree, Aug 9, 2020.

  1. ggooxxoorree

    ggooxxoorree

    Joined:
    Mar 7, 2018
    Posts:
    3
    Hello guys, i need a shader that would desaturate a color channel, and hopefully make whole sprite look yellow.The problem is when I try to change sprites color to yellow, it just adds up to color, and i wanted it to look only in yellow tones . Sorry for my bad english and I would really appreciate any help!



     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    If you want to tint only part of something, you'll need some kind of mask. Usually this comes in the form of another texture, though this can be a pain for sprites if you're using an atlas, as you can't use Unity's built in auto-atlasing. You have to manually atlas your sprites and have an identically laid out atlas that has your masks, and a custom sprite shader that lerps between the colored and uncolored parts. You could also look into chroma key shaders for how they calculate a mask by converting the RGB color into some other color space (HSV or HSL) and looking for areas of a specific hue or within some "range" of that hue.

    The alternative that doesn't require any custom shaders is to split up your sprites into two, the base you don't want to be colored, and the tinted part as a separate sprite you put on top.
     
  3. ggooxxoorree

    ggooxxoorree

    Joined:
    Mar 7, 2018
    Posts:
    3
    Thank you for response, i actually dont mind changing the black line and handle. can i achieve something like this using shaders?

     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The default sprite shader already colors everything whatever color you assign. The issue is computer graphics are handled as RGB color values, and yellow is a combination of red & green. That means anything in the texture that is red or green will still be red or green. Only the areas that are white or blue will really change.

    If you want it to change everything to yellow, you'll need to use a shader that desaturates the sprite to greyscale before multiplying by yellow. There are several around on the forums and elsewhere, like this one:
    https://forum.unity.com/threads/sprite-shader-with-greyscale.222693/#post-3103196
     
  5. ggooxxoorree

    ggooxxoorree

    Joined:
    Mar 7, 2018
    Posts:
    3
    Thanks! i will try that