Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

use the tint color to lighten up a sprite

Discussion in 'Shaders' started by rfuhrer, Apr 12, 2016.

  1. rfuhrer

    rfuhrer

    Joined:
    Oct 2, 2015
    Posts:
    49
    Hey, I really have no clue how to solve this. But I would like to use the tint color on a sprite but it should lighten up the sprite not darken it, like it does it right now. I would like to lighten up the sprite the farther they are in the background. I work on a 2D game I would like to use this to fake depth.

    Any help would be very much appreciated.
     
  2. rfuhrer

    rfuhrer

    Joined:
    Oct 2, 2015
    Posts:
    49
    Does no one have an idea? Its not nessesary to use the tint color, it could also work differently if it does what I need.
     
  3. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Everything you need is in the UIDefault Shader. Just add the color passed from the vert program instead of multiplying it onto the texture.
     
  4. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    Take a look at the blend types in Photoshop. I would probably go for "Screen" ( 1 - (1 - A) * (1 - B)), and then you can lerp the result with your main color based on distance.

    You will need to edit the shader, and if you haven't messed with shaders much yet, now is a great time to learn.
     
    dtmhawk likes this.
  5. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    What you need is an HDR tint color, allowing it to go above 1. There are many solutions to this, and depending on what shader your using it might be enough to simply replace the GUI for the shader!
     
  6. rfuhrer

    rfuhrer

    Joined:
    Oct 2, 2015
    Posts:
    49
    Thanks for the replays. Right now I use the default Sprite diffuse shader.
    To be honest I have never messed with shaders this is my first attempt. I have read a few articles but getting into it is difficult. So all of your solutions sound good to me. But don't know where to start.

    @brownboot67
    - What is a UIDefault shader? What do you mean by vert progroam?

    @CaptainScience
    - Screen could work. Overlay or softLight would be good as well.
    I would love to learn more about programming shaders. Do you know any good tutorials. I found this here quite good:
    https://unity3d.com/learn/tutorials/topics/graphics/gentle-introduction-shaders

    @Zicandar
    Hm, how would you approach this? Going above 1 would also mean making it more complex, right? I think right now the color value gets subtracted somehow using the tint. What I would need is more like an addition or a multiply. As @CaptainScience said, I think it should be easy to find out how these photoshop modes work. But what is performant and how do I get the shader to do it?

    My plan was take the diffuse sprite shader and try to modify it. But there it starts. Searching for shaders in unity I only find the opaqe one... and only the diffuse one has the tint color.

    Thanks again for taking the time and looking into it. Any further help is greatly appreciated.
     
  7. BillyMFT

    BillyMFT

    Joined:
    Mar 14, 2013
    Posts:
    178
    Did you get anywhere with this?
     
  8. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Well, a tint IS a multiply, but if you multiply by less then 1, it'l always get darker. (HDR generally means allowing colors over 1 (white))
     
  9. rfuhrer

    rfuhrer

    Joined:
    Oct 2, 2015
    Posts:
    49
    Hm, no not really. What I do right now is I use a second colored overlay for some of the images and make them more transparent to closer they get to the cam. This is not ideal since it costs memory.

    @Zicandar ah right, did overlook that the value is lower then 1.

    Well, I am not sure how to approach this.