Search Unity

(2D Sprites) Change only the Hue, and leave Saturation and Lighting the same.

Discussion in 'Shaders' started by Gunging, May 9, 2017.

  1. Gunging

    Gunging

    Joined:
    Sep 6, 2016
    Posts:
    139
    When you change the color of a sprite, all the colors are added/multiplied according to the shader, but is it possible to only change the hue?

    I can illustrate my idea with the following:

    I especifically have this Lazer segment sprite, and you can see its green.


    When changing the color to red, this happens:


    So to get what I really wanted, I have to make a new sprite:

    *It is also a different gameObject, because its the "red lazer", just ignore the rest of the components.


    In paint.net, which is what I use, there is this tab:

    And if I move the Hue, the lazer changes colors as I wanted:


    Is there a way to achieve this in Unity? Thanks in advance.
     
  2. UziMonkey

    UziMonkey

    Joined:
    Nov 7, 2012
    Posts:
    206
    Make your sprite greyscale. This will allow you to change it to any color.
     
  3. Gunging

    Gunging

    Joined:
    Sep 6, 2016
    Posts:
    139
    Thank you, let me try it
     
  4. Gunging

    Gunging

    Joined:
    Sep 6, 2016
    Posts:
    139
    So now I made


    But when I change the color it does


    Any other suggestions?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    You'll need a custom shader for this that does a photoshop style overlay rather than a straight multiply of the color and the base texture. Some people will do a basic "2x multiply" which is a cheap approximation, but doesn't work if you're using heavily saturated colors.
     
    UziMonkey likes this.
  6. UziMonkey

    UziMonkey

    Joined:
    Nov 7, 2012
    Posts:
    206
    Honestly unless you need lasers of any color, I'd just make 8 or 10 or however many you need different laser colors in your image editing program. I see the problem you're having with using a straight up sprite color and a shader will work fine to compensate for that, but unless you already know how to write shaders you'll probably spend less time making those images than you will writing the shader.
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    You can also do the hack of using two sprites; one tinted the color for the base, and a white one on top to make the core.
     
  8. Gunging

    Gunging

    Joined:
    Sep 6, 2016
    Posts:
    139
    Yeah, I know the 2 sprite hack, but wont work in everything Im trying to use the solution of this for, as Im having the same issue with a particle, and I believe you cant do that to particles.


    Thanks guys, I´ll have to make the sprite-for-every-color thing.
     
    Last edited: May 10, 2017