Unity shader-溶解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/y90o08u28/article/details/87262908

 rongjie1rongjie0

Shader "PengLu/DissolveVF" {
    Properties{

        _MainTex("Base (RGB)", 2D) = "white" {}
        _DissolveTex("DissolveTex (RGB)", 2D) = "white" {}
        _LightTex("DissolveTex (RGB)", 2D) = "white" {}

        _Tile("DissolveTile", Range(0.1, 1)) = 1

        _Amount("DissAmount", Range(0, 1)) = 0.5
        _DissSize("DissSize", Range(0, 1)) = 0.1

        _DissColor("DissColor", Color) = (1,0,0,1)
        _AddColor("AddColor", Color) = (1,1,0,1)

        _LightPra("LightColor", Range(1, 2)) = 1

    }

        SubShader{
            Tags { "RenderType" = "Opaque" "LightMode" = "ForwardBase"}
            LOD 100

            Pass {
                CGPROGRAM
                    #pragma vertex vert
                    #pragma fragment frag
                    #pragma multi_compile_fog

                    #include "UnityCG.cginc"
                    #include "Lighting.cginc"

                    sampler2D _MainTex,_DissolveTex,_LightTex;
                    fixed4 _MainTex_ST,_DissolveTex_ST, _LightTex_ST;
                    half _Tile, _LightPra,_Amount,_DissSize;
                    half4 _DissColor,_AddColor;


                    struct appdata_t {
                        float4 vertex : POSITION;
                        float2 texcoord : TEXCOORD0;
                        float2 texcoord1 : TEXCOORD1;
                        float3 normal : NORMAL;
                    };

                    struct v2f {
                        float4 vertex : SV_POSITION;
                        half2 texcoord : TEXCOORD0;
                        half2 texcoord1 : TEXCOORD1;
                        fixed3 color : COLOR;
                    };

                    v2f vert(appdata_t v)
                    {
                        v2f o;
                        o.vertex = UnityObjectToClipPos(v.vertex);
                        o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                        o.texcoord1 = TRANSFORM_TEX(v.texcoord1, _MainTex);
                        //o.texcoord1 = v.texcoord1;
                        UNITY_TRANSFER_FOG(o,o.vertex);

                        fixed3 worldNormal = normalize(mul(v.normal, (float3x3)unity_WorldToObject));
                        fixed3 worldLight = normalize(_WorldSpaceLightPos0.xyz);
                        fixed3 diffuse = _LightColor0.rgb * saturate(dot(worldNormal, worldLight));
                        o.color =  diffuse; //漫射光

                        return o;
                    }

                    fixed4 frag(v2f i) : SV_Target
                    {
                        fixed4 col = tex2D(_MainTex, i.texcoord);
                        fixed4 col_light = tex2D(_LightTex, i.texcoord1);
                        float ClipTex = tex2D(_DissolveTex, i.texcoord1 / _Tile).r;
                        float ClipAmount = ClipTex - _Amount;
                        if (_Amount > 0)
                        {
                            if (ClipAmount <= 0)
                            {
                                clip(-0.1);
                            }
                            else {
                                if (ClipAmount < _DissSize)
                                {
                                    float4 finalColor = lerp(_DissColor,_AddColor,ClipAmount / _DissSize) * 2;
                                    col = col * finalColor;
                                }
                            }
                        }
                        UNITY_APPLY_FOG(i.fogCoord, col);
                        UNITY_OPAQUE_ALPHA(col.a);
                        return col* col_light*_LightPra;
                    }
                ENDCG
            }
        }

}

本人qq:344810449,一起研究技术。

猜你喜欢

转载自blog.csdn.net/y90o08u28/article/details/87262908