[Shader] special effect on distorted energy hood and special effect on shader Distortion

Source: Internet
Author: User
Tags mul

[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 }}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.