Shader "Custom/GlassBlur" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _BlurSize ("Blur Size", Range(0, 10)) = 1.0 _Intensity ("Intensity", Range(0, 1)) = 0.5 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGINCLUDE #include "UnityCG.cginc" sampler2D _MainTex; float4 _MainTex_TexelSize; float _BlurSize; float _Intensity; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; }; v2f vert(appdata_img v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = v.texcoord; return o; } // 高斯模糊函数 float4 gaussianBlur(v2f i, float2 direction) { float4 color = float4(0, 0, 0, 0); float2 offsets[9] = { float2(-1, -1), float2(0, -1), float2(1, -1), float2(-1, 0), float2(0, 0), float2(1, 0), float2(-1, 1), float2(0, 1), float2(1, 1) }; float weights[9] = { 0.05, 0.1, 0.05, 0.1, 0.4, 0.1, 0.05, 0.1, 0.05 }; for(int j = 0; j < 9; j++) { float2 uv = i.uv + offsets[j] * _MainTex_TexelSize.xy * _BlurSize * direction; color += tex2D(_MainTex, uv) * weights[j]; } return color; } ENDCG // 水平模糊 Pass Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag float4 frag(v2f i) : SV_Target { return gaussianBlur(i, float2(1, 0)); } ENDCG } // 垂直模糊 Pass Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag float4 frag(v2f i) : SV_Target { return gaussianBlur(i, float2(0, 1)); } ENDCG } // 混合 Pass Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag sampler2D _BlurTex; float4 frag(v2f i) : SV_Target { float4 original = tex2D(_MainTex, i.uv); float4 blurred = tex2D(_BlurTex, i.uv); return lerp(original, blurred, _Intensity); } ENDCG } } FallBack "Diffuse" }