Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Nova/VerticalFogAnimated"
- {
- Properties
- {
- _Color("Main Color", Color) = (1, 1, 1, .5)
- _IntersectionThresholdMax("Intersection Threshold Max", float) = 1
- _AlphaMask("Alpha Mask", 2D) = "white" {}
- // variable_name("name in inspector", variable_type) = initial_value
- _HorizontalSpeed("Horizontal Speed", Float) = 1
- _VerticalSpeed("Vertical Speed", Float) = 0
- }
- SubShader
- {
- Tags { "Queue" = "Transparent" "RenderType"="Transparent" }
- Pass
- {
- Blend SrcAlpha OneMinusSrcAlpha
- ZWrite Off
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma multi_compile_fog
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- half4 uv : TEXCOORD0;
- };
- struct v2f
- {
- half4 uv : TEXCOORD0;
- float4 scrPos : TEXCOORD1;
- UNITY_FOG_COORDS(1)
- float4 vertex : SV_POSITION;
- };
- sampler2D _CameraDepthTexture, _AlphaMask;
- float4 _Color;
- float _IntersectionThresholdMax;
- // here we declare variables inside CG program
- half _HorizontalSpeed, _VerticalSpeed;
- v2f vert(appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.scrPos = ComputeScreenPos(o.vertex);
- o.uv = v.uv;
- UNITY_TRANSFER_FOG(o,o.vertex);
- return o;
- }
- fixed GetAlphaMult(half4 uv0, sampler2D alphamask)
- {
- fixed mainMask = 1 - tex2D(alphamask, uv0.xy).g;
- float time = _Time.x;
- uv0.x += frac(time * _HorizontalSpeed);
- uv0.y += frac(time * _VerticalSpeed);
- fixed animationMask = 1 - tex2D(alphamask, uv0.xy).r;
- return mainMask * animationMask;
- }
- half4 frag(v2f i) : SV_TARGET
- {
- float depth = LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)));
- float diff = saturate(_IntersectionThresholdMax * (depth - i.scrPos.w));
- fixed4 col = lerp(fixed4(_Color.rgb, 0.0), _Color, diff * diff * diff * (diff * (6 * diff - 15) + 10));
- col.a *= GetAlphaMult(i.uv, _AlphaMask);
- UNITY_APPLY_FOG(i.fogCoord, col);
- return col;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement