Created
July 25, 2018 02:39
-
-
Save cjacobwade/f827a2f3be440d646a3b58721e5b6efe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' | |
Shader "Custom/Airwave" | |
{ | |
Properties | |
{ | |
_TintColor("Color", Color) = (1, 1, 1, 1) | |
_AlphaMask("Alpha Mask", 2D) = "white" {} | |
_WaveNormal("Wave Normal", 2D) = "white" {} | |
_WaveStrength("Wave Strength", Float) = 0.3 | |
_InvFade("Soft Particles Factor", Range(0, 3)) = 1 | |
} | |
SubShader | |
{ | |
// Draw ourselves after all opaque geometry | |
Tags{ "Queue" = "Transparent+20" "RenderType"="Transparent" } | |
// Grab the screen behind the object into _BackgroundTexture | |
GrabPass {} | |
Blend SrcAlpha OneMinusSrcAlpha | |
Zwrite Off | |
// Render the object with the texture generated above, and invert the colors | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_particles | |
#include "UnityCG.cginc" | |
sampler2D _GrabTexture; | |
sampler2D _WaveNormal; | |
half _WaveStrength; | |
sampler2D _AlphaMask; | |
half4 _TintColor; | |
// Soft particles | |
sampler2D_half _CameraDepthTexture; | |
half _InvFade; | |
struct v2f | |
{ | |
half4 grabPos : TEXCOORD0; | |
half4 pos : SV_POSITION; | |
half4 color : COLOR; | |
half2 uv_WaveNormal : TEXCOORD1; | |
#ifdef SOFTPARTICLES_ON | |
half4 projPos : TEXCOORD2; | |
#endif | |
}; | |
v2f vert(appdata_full v) | |
{ | |
v2f o; | |
// use UnityObjectToClipPos from UnityCG.cginc to calculate | |
// the clip-space of the vertex | |
o.pos = UnityObjectToClipPos(v.vertex); | |
#ifdef SOFTPARTICLES_ON | |
o.projPos = ComputeScreenPos(o.pos); | |
COMPUTE_EYEDEPTH(o.projPos.z); | |
#endif | |
// use ComputeGrabScreenPos function from UnityCG.cginc | |
// to get the correct texture coordinate | |
o.grabPos = ComputeGrabScreenPos(o.pos); | |
o.color = v.color; // Use vertex color to get the alpha from particle color | |
o.uv_WaveNormal = v.texcoord; | |
return o; | |
} | |
half4 frag(v2f i) : SV_Target | |
{ | |
#ifdef SOFTPARTICLES_ON | |
half sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))); | |
half partZ = i.projPos.z; | |
half fade = saturate(_InvFade * (sceneZ - partZ)); | |
i.color.a *= fade; | |
#endif | |
half4 alphaMask = tex2D(_AlphaMask, i.uv_WaveNormal.xy); | |
half3 wave = UnpackNormal(tex2D(_WaveNormal, i.uv_WaveNormal.xy)); | |
i.grabPos.xy += wave.xy / wave.z * _WaveStrength * i.color.a * _TintColor.a; | |
half4 bgcolor = tex2Dproj(_GrabTexture, i.grabPos); | |
bgcolor.rgb *= _TintColor.rgb; | |
bgcolor.a = alphaMask.r; | |
return bgcolor; | |
} | |
ENDCG | |
} | |
} | |
FallBack "Lambert" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment