Shader "Custom/RippleEffect"{ Properties{ _MainTex("Base", 2D) = "white" {} _GradTex("Gradient", 2D) = "white" {} _Reflection("Reflection Color", Color) = (0, 0, 0, 0) _Params1("Parameters 1", Vector) = (1, 1, 0.8, 0) _Params2("Parameters 2", Vector) = (1, 1, 1, 0) _Drop1("Drop 1", Vector) = (0.49, 0.5, 0, 0) _Drop2("Drop 2", Vector) = (0.50, 0.5, 0, 0) _Drop3("Drop 3", Vector) = (0.51, 0.5, 0, 0) _SeaLevel("SeaLevel", Range(-1.0, 1.0)) = -1.0 } SubShader { Tags{ "RenderType"="Transparent" "Queue"="Transparent" } Blend SrcAlpha OneMinusSrcAlpha Cull Off Pass { HLSLPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 3.0 #pragma multi_compile_instancing #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"

        #define PI 3.141592653589793

        Texture2D<float4> _MainTex;
        sampler2D _MainTexSampler;
        Texture2D<float4> _GradTex;
        sampler2D _GradTexSampler;
        float4 _Params1;
        float4 _Params2;
        float3 _Drop1;
        float3 _Drop2;
        float3 _Drop3;
        float _SeaLevel;

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

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

        float wave(float2 position, float2 origin, float time)
        {
            float d = length(position - origin);
            float t = time - d * _Params1.z;
            if (_SeaLevel > 0 && position.y > _SeaLevel)
            {
                return 0;
            }
            return (tex2D(_GradTexSampler, float2(t, 0)).a - 0.5f) * 2;
        }

        float allwave(float2 position)
        {
            return
                wave(position, _Drop1.xy, _Drop1.z) +
                wave(position, _Drop2.xy, _Drop2.z) +
                wave(position, _Drop3.xy, _Drop3.z);
        }

        VertexOutput vert(VertexInput input)
        {
            VertexOutput output;
            output.vertex = UnityObjectToClipPos(input.vertex);
            output.uv = input.uv * _Params1.xy;
            return output;
        }

        float4 frag(VertexOutput input) : SV_Target
        {
            const float2 dx = float2(0.01f, 0);
            const float2 dy = float2(0, 0.01f);
            float2 p = input.uv;
            float w = allwave(p);
            float2 dw = float2(allwave(p + dx) - w, allwave(p + dy) - w);
            float2 duv = dw * _Params2.xy * 0.2f * _Params2.z;
            float4 c = tex2D(_MainTexSampler, input.uv + duv);
            float fr = pow(length(dw) * 3 * _Params2.w, 3);
            return lerp(c, _Reflection, fr);
        }
        ENDHLSL
    }
}
Shader CustomRippleEffect Properties _MainTexBase 2D = white _GradTexGradient 2D = white _ReflectionReflection Color Color = 0 0 0 0 _Params1Parameters 1 Vector =

原文地址: http://www.cveoy.top/t/topic/i1QA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录