Search Unity

Crossfade between 2 textures in Standard Shader

Discussion in 'Shaders' started by XeOniFiCaTiOn, Nov 3, 2015.

  1. XeOniFiCaTiOn

    XeOniFiCaTiOn

    Joined:
    May 7, 2013
    Posts:
    17
    Hi Guys,

    I am trying to build an extension to the standard shader. I would like the final albiedo to be a blend between the 2 textures that i have.

    I am always getting a black object when i decrease transparency completely on the object that has this shrader.

    Kindly shed some light on what i am doing wrong here and help me achieve true transparency with a blended shader:


    Shader "CrossFade"
    {
    Properties
    {
    _Blend ( "Blend", Range ( 0, 1 ) ) = 0
    _Color ( "Main Color", Color ) = ( 1, 1, 1, 1 )
    _MainTex ( "Texture 1", 2D ) = "white" {}
    _Texture2 ( "Texture 2", 2D ) = "white" {}
    }

    SubShader
    {
    Tags { "RenderType"="Fade" "RenderQueue"="Geometry" }
    LOD 300
    Pass
    {
    SetTexture[_MainTex]
    SetTexture[_Texture2]
    {
    ConstantColor ( 0, 0, 0, [_Blend] )
    Combine texture Lerp( constant ) previous
    }
    }

    CGPROGRAM
    #pragma surface surf Standard


    sampler2D _MainTex;
    sampler2D _Texture2;
    fixed4 _Color;
    float _Blend;

    struct Input
    {
    float2 uv_MainTex;
    float2 uv_Texture2;
    };

    void surf ( Input IN, inout SurfaceOutputStandard o )
    {
    fixed4 t1 = tex2D( _MainTex, IN.uv_MainTex ) * _Color;
    fixed4 t2 = tex2D ( _Texture2, IN.uv_Texture2 ) * _Color;
    o.Albedo = lerp( t1, t2, _Blend );
    o.Alpha = _Color.a;
    }
    ENDCG
    }
    FallBack "Diffuse"
    }

    thanks,
    regards
    XeOn
     
    Last edited: Nov 4, 2015