layering/adding/blending two textures

Here we define two textures -cat and dog. I actually had a few issues using the usual _MainTex name.

Something new - we use a Toggle to turn on and off the Decal texture - multiplying the dog texture by the 0 or 1 value. The thing of note is at the o.Albedo calculation, where we check if the alpha channel of the b texture (which is the dog one) has a value above 0.9 (we allow for some float-value accuracy as the alpha might not be exactly 1!), if so we use the b texture & if not, we use the a texture. We could check the red channel or blue or green if we liked..

 

 

 Shader "Dave/basictextureblend"
{
    Properties{
        _cat("cat", 2D) = "red"{}
        _dog("dog",2D) = "blue"{}
        [Toggle]_ShowDecal("Show Decal",Float)=0


    }

    SubShader{
        Tags{"Queue" = "Geometry"}
        CGPROGRAM
        #pragma surface surf Lambert
        sampler2D _cat;
        sampler2D _dog;
        float _ShowDecal;
        struct Input {
            float2 uv_cat;
            float2 uv_dog;

        };

        void surf(Input IN, inout SurfaceOutput o) {
            float4 a = tex2D(_cat, IN.uv_cat);
            float4 b = tex2D(_dog, IN.uv_cat)*_ShowDecal;
            o.Albedo = b.a>0.9 ? b.rgb :a.rgb;


        }


        ENDCG
    }


    FallBack "Diffuse"
}

Comments

Popular posts from this blog

setting VFX graph properties using C#