URP Shader: Ripple Effect
{
"Properties": {
"_MainTex": {"Base": "2D", "Default": "white"},
"_GradTex": {"Gradient": "2D", "Default": "white"},
"_Reflection": {"Reflection Color": "Color", "Default": "(0, 0, 0, 0)"},
"_Params1": {"Parameters 1": "Vector", "Default": "(1, 1, 0.8, 0)"},
"_Params2": {"Parameters 2": "Vector", "Default": "(1, 1, 1, 0)"},
"_Drop1": {"Drop 1": "Vector", "Default": "(0.49, 0.5, 0, 0)"},
"_Drop2": {"Drop 2": "Vector", "Default": "(0.50, 0.5, 0, 0)"},
"_Drop3": {"Drop 3": "Vector", "Default": "(0.51, 0.5, 0, 0)"},
"_SeaLevel": {"SeaVevel": "Float", "Default": "-1.0"}
},
"SubShader": {
"Tags": {
"RenderType": "Opaque",
"Queue": "Geometry"
},
"RenderPipeline": {
"SubShader": {
"Pass": {
"HLSLPROGRAM": {
"#pragma vertex vert",
"#pragma fragment frag",
"#pragma target 3.0",
"\n",
"#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInstancing.hlsl"",
"#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"",
"\n",
"struct appdata\n{\n float4 vertex : POSITION;\n float2 uv : TEXCOORD0;\n};",
"\n",
"struct v2f\n{\n float2 uv : TEXCOORD0;\n UNITY_VERTEX_INPUT_INSTANCE_ID\n};",
"\n",
"sampler2D _MainTex;",
"float2 _MainTex_TexelSize;",
"sampler2D _GradTex;",
"half4 _Reflection;",
"float4 _Params1;",
"float4 _Params2;",
"float3 _Drop1;",
"float3 _Drop2;",
"float3 _Drop3;",
"float _SeaLevel;",
"\n",
"float wave(float2 position, float2 origin, float time)\n{\n float d = length(position - origin);\n float t = time - d * _Params1.z;\n if (_SeaLevel > 0 && position.y > _SeaLevel)\n {\n return 0;\n }\n return (tex2D(_GradTex, float2(t, 0)).a - 0.5f) * 2;\n}\n",
"\n",
"float allwave(float2 position)\n{\n return\n wave(position, _Drop1.xy, _Drop1.z) +\n wave(position, _Drop2.xy, _Drop2.z) +\n wave(position, _Drop3.xy, _Drop3.z);\n}\n",
"\n",
"float4 frag(v2f i) : SV_Target\n{\n const float2 dx = float2(0.01f, 0);\n const float2 dy = float2(0, 0.01f);\n float2 p = i.uv * _Params1.xy;\n float w = allwave(p);\n float2 dw = float2(allwave(p + dx) - w, allwave(p + dy) - w);\n float2 duv = dw * _Params2.xy * 0.2f * _Params2.z;\n float4 c = tex2D(_MainTex, i.uv + duv);\n float fr = pow(length(dw) * 3 * _Params2.w, 3);\n return lerp(c, _Reflection, fr);\n}\n",
"\n",
"v2f vert(appdata v)\n{\n v2f o;\n o.uv = v.uv;\n UNITY_SETUP_INSTANCE_ID(v);\n return o;\n}\n",
"\n",
"ENDHLSL"
}
}
}
}
}
原文地址: https://www.cveoy.top/t/topic/nbOu 著作权归作者所有。请勿转载和采集!