Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Two texture blend with third texture alpha (lerp)

Discussion in 'Shaders' started by metervara, Mar 3, 2010.

  1. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Can't get this to work, should it or am i doing something wrong

    1. draw _MainTex
    2. draw alpha component of Mask using colorMask a. Result is _Maintex.rgb and _Mask.a?
    3. lerp _Effect texture -> previous color should be _MainTex and previous alpha should be _Mask?

    Code (csharp):
    1. Shader "Hidden/Mask Composit" {
    2.     Properties {
    3.         _MainTex ("", RECT) = "" {}
    4.         _Mask ("", RECT) = "" {}
    5.         _Effect ("", RECT) = "" {}
    6.    }
    7.     SubShader {
    8.         ZTest Always Cull Off ZWrite Off Fog { Mode Off }
    9.         Pass{
    10.             SetTexture[_MainTex]{
    11.                 combine texture
    12.             }
    13.         }
    14.         Pass{
    15.             ColorMask A
    16.             SetTexture[_Mask]{
    17.                 combine texture
    18.             }
    19.         }
    20.         Pass{
    21.             SetTexture[_Effect]{
    22.                 combine texture lerp(previous) previous
    23.             }
    24.         }
    25.     }
    26. Fallback Off
    27. }
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    "previous" refers to the result of the previous texture operation in the current pass only. It will probably be black if you try and use it in the first texture operation. Try:

    Code (csharp):
    1. Shader "Hidden/Mask Composit" {
    2.    Properties {
    3.          _MainTex ("", RECT) = "" {}
    4.          _Mask ("", RECT) = "" {}
    5.          _Effect ("", RECT) = "" {}
    6.    }
    7.    SubShader {
    8.       ZTest Always Cull Off ZWrite Off Fog { Mode Off }
    9.       Pass{
    10.          SetTexture[_MainTex]{
    11.             combine texture
    12.          }
    13.          SetTexture[_Mask]{
    14.             combine previous, texture
    15.          }
    16.          SetTexture[_Effect]{
    17.             combine texture lerp(previous) previous
    18.          }
    19.       }
    20.    }
    21. Fallback Off
    22. }
     
  3. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    thanks