Search Unity

Shader for transparent image and tinted background

Discussion in 'Shaders' started by 1GR3, Aug 12, 2014.

  1. 1GR3

    1GR3

    Joined:
    Aug 2, 2013
    Posts:
    5
    I'm trying to achieve pretty simplified design for a logic game where active tiles have simple white symbols and they suppose to have tinted background which can be easily manipulated programatically.
    The attached image represents raw png (on the left) and the appearance I would like to achieve (on the right)
    Screen Shot 2014-08-12 at 18.36.29.png
    Is it possible to achieve that without creating double game object, one behind the other?
    Thank you in advance!
     
  2. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    yes it should be pretty easy, except that it's confusing what your starting files are, it's just a texture file on the left, and on right you want to have i.e. blue? tinted is the blue area?

    it's very easy, you would have to write a small number of lines on top of a basic or existing shader that you are using, logically, you have white picture with only alpha values? just say in the shader... for every pixel, if pixelxy alpha value = 1, then pixel color.alphavalue *= 0.5 to make it semi transparent, and pixel color.rbg = float3(0,0,1); to make the same area blue.

    look on google for shaders with these keywords to fined examples of other transparent shaders.
    Code (csharp):
    1.  
    2.     }
    3.     SubShader {
    4.         Tags {"Queue"="Transparent" "RenderType"="Transparent"}
    5.         LOD 200
    6.  
    7.         Blend OneMinusSrcAlpha One
    8.         CGPROGRAM
    9.  
     
  3. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    in the shader:
    lerp(bluecolor, whitecolor, alphavalue);

    this should paint the respective quad in blue or white depending on the alpha value of the original image, you don't even have to use any special blend