Search Unity

Overlay one texture to another.

Discussion in 'Shaders' started by Carrasco, Jul 2, 2015.

  1. Carrasco

    Carrasco

    Joined:
    Feb 10, 2015
    Posts:
    4
    Hello guys, I'm new in shader programming and I don't know exactly how i do to overlay one texture to another without multiply them. To explain better i will use two images as examples.

    It's what is happening


    what i expect


    Any help we'll be useful, thank you!
     

    Attached Files:

  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    You'd want to lerp (linearly interpolate) between the base colour and the overlay colour via the transparent value of the overlay colour.

    That means your overlay colour map would need an alpha channel, with white where you want it to appear and black where you don't (and shades of grey blend between those two extremes).

    Code (csharp):
    1. fixed3 baseColor; // This is whatever holds the base colour.
    2. fixed4 overlayColor; // This holds the overlay colour and it's transparency in the alpha channel.
    3. fixed3 result = lerp (baseColor, overlayColor.rgb, overlayColor.a);
     
  3. Carrasco

    Carrasco

    Joined:
    Feb 10, 2015
    Posts:
    4
    Ok, i did that and it works, but it requires the overlay texture when i apply the result to the o.albedo. In this case I have to do a if statement or something else? How it would be?
     
  4. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    I'm not certain what you mean... you want the overlay texture to be optional?
     
  5. Carrasco

    Carrasco

    Joined:
    Feb 10, 2015
    Posts:
    4