unity shader 溶解,上下左右,cutoff

思玉發表於2020-11-18

unity shader 溶解,上下左右,cutoff
在這裡插入圖片描述


Shader "cutoff" {
    Properties {
        _Cutoff ("Cutoff", Float ) = 0
        _Mask ("Mask", 2D) = "white" {}
        _Diffues ("Diffues", 2D) = "white" {}
     
    }
    SubShader {
        Tags {
            "Queue"="AlphaTest"
            "RenderType"="TransparentCutout"
        }
        Pass {
            Name "ForwardBase"
            Tags {
                "LightMode"="ForwardBase"
            }            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            #include "AutoLight.cginc"
            uniform float _Cutoff;
            uniform sampler2D _Mask; uniform float4 _Mask_ST;
            uniform sampler2D _Diffues; uniform float4 _Diffues_ST;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 posWorld : TEXCOORD1;
                LIGHTING_COORDS(2,3)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.posWorld = mul(unity_ObjectToWorld, v.vertex);
                o.pos = UnityObjectToClipPos(v.vertex);
                TRANSFER_VERTEX_TO_FRAGMENT(o)
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {
                float clipValue = 10.0;
                float4 _Mask_var = tex2D(_Mask,TRANSFORM_TEX(i.uv0, _Mask));
                float clip_var = clamp(((_Cutoff+(_Cutoff*(1.0 - (abs(((_Cutoff*clipValue)-clipValue))*i.uv0.g))))-_Mask_var.r),-1,1);
                clip(clip_var - 0.5);

				float4 _Diffues_var = tex2D(_Diffues,TRANSFORM_TEX(i.uv0, _Diffues));
                return _Diffues_var;
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}

相關文章