[Shader] special effect on distorted energy hood and special effect on shader Distortion
Shader "Custom/ForceField" {Properties {_ Color ("Color", Color) = (0, 0, 0) _ NoiseTex ("NoiseTexture", 2D) = "white" {} // distortion degree _ DistortStrength ("DistortStrength", Range (0.2) = // distortion frequency _ DistortTimeFactor ("DistortTimeFactor", Range )) = 0.2 _ RimStrength ("RimStrength", Range (0, 10) = 2 _ IntersectPower ("IntersectPower", Range (0, 3 )) = 2} SubShader {ZWrite Off Cull Off Blend SrcAlpha OneMinusSrcAlpha Tags {"RenderType" = "Transparent" "Queue" = "Transparent"} GrabPass {"_ GrabTempTex"} Pass {CGPROGRAM # pragma target 3.0 # pragma vertex vert # pragma fragment frag # include "UnityCG. cginc "struct appdata {float4 vertex: POSITION; float2 uv: cursor; float3 normal: NORMAL;}; struct v2f {float4 vertex: SV_POSITION; float2 uv: TEXCOORD0; float4 screenPos: TEXCOORD1; float4 grabPos: TEXCOORD2; float3 normal: NORMAL; float3 viewDir: TEXCOORD3;}; sampler2D _ GrabTempTex; float4 _ cursor; sampler2D _ NoiseTex; float4 _ cursor; float _ cursor; float _ DistortTimeFactor; float _ RimStrength; float _ IntersectPower; sampler2D _ CameraDepthTexture; v2f vert (appdata v) {v2f o; o. vertex = UnityObjectToClipPos (v. vertex); o. grabPos = ComputeGrabScreenPos (o. vertex); o. uv = TRANSFORM_TEX (v. uv, _ NoiseTex); o. screenPos = ComputeScreenPos (o. vertex); COMPUTE_EYEDEPTH (o. screenPos. z); o. normal = UnityObjectToWorldNormal (v. normal); o. viewDir = normalize (UnityWorldSpaceViewDir (mul (unity_ObjectToWorld, v. vertex); return o;} fixed4 _ Color; fixed4 frag (v2f I): SV_Target {// obtain existing depth information, at this time, the depth scheme does not have information about the force field. // determine the intersection float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ (_ CameraDepthTexture, UNITY_PROJ_COORD (I. screenPos); float partZ = I. screenPos. z; float diff = sceneZ-partZ; float intersect = (1-diff) * _ IntersectPower; // ring float3 viewDir = normalize (UnityWorldSpaceViewDir (mul (unity_ObjectToWorld, I. vertex); float rim = 1-abs (dot (I. normal, normalize (I. viewDir) * _ RimStrength; float glow = max (intersect, rim); // twist float4 offset = tex2D (_ NoiseTex, I. uv-_ Time. xy * _ DistortTimeFactor); I. grabPos. xy-= offset. xy * _ DistortStrength; fixed4 color = tex2Dproj (_ GrabTempTex, I. grabPos); fixed4 col = _ Color * glow + color; return col;} ENDCG }}}