How to layer textures in shader?

How do i properly layer textures in unity using fragment shaders?

In photoshop

Right now what i do in the shader is lerp the BG,TOP, using TOP ALPHA as T. But the result is not the same when i put the BG on sprite and the TOP in other sprite at top (what im trying to achieve).

Any ideas how to do this in a shader? can i print the BF in one pass and the TOP in another pass?

Help!

1 Like

ok i did it with 2 pass.

Using the lerp technique always gave some small artifacts (black borders).

now im layering like this.

SubShader
    {
        Tags { "RenderType"="Opaque" }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
           
            fixed4 frag (v2f_img i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                return col;
            }
            ENDCG
        }

        Tags {  "Queue"="Transparent" "RenderType"="Transparent" }
        Blend SrcAlpha OneMinusSrcAlpha
        Pass
        {
            CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex2;
   
            fixed4 frag (v2f_img i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex2, i.uv);
                return col;
            }
            ENDCG
        }
    }
2 Likes