Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Unlit/MotionExtractionShader"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- _CurrentTex ("Current Texture", 2D) = "white" {}
- _DelayedTex ("Delayed Texture", 2D) = "white" {}
- _GradientTex("Gradient Texture", 2D) = "white" {}
- _AltGradientTex("Alt Gradient Texture", 2D) = "white" {}
- _GradientMaxValue("Gradient Remap Max Value", Range(0, 1)) = 1.0
- _AlphaMultiplier("Alpha", Range(0,1)) = 1.0
- }
- SubShader
- {
- Tags { "RenderType"="Transparent" }
- Blend SrcAlpha OneMinusSrcAlpha
- LOD 100
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float4 vertex : SV_POSITION;
- };
- sampler2D _CurrentTex;
- sampler2D _DelayedTex;
- sampler2D _GradientTex;
- sampler2D _AltGradientTex;
- float _GradientMaxValue;
- float _AlphaMultiplier = 1;
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = v.uv;
- return o;
- }
- fixed4 frag (v2f i) : SV_Target
- {
- // sample the texture
- fixed4 currentColor = tex2D(_CurrentTex, i.uv);
- fixed4 delayedColor = tex2D(_DelayedTex, i.uv);
- float delta = distance(currentColor, delayedColor);
- fixed4 col;
- float gradT = delta / _GradientMaxValue;
- const fixed4 mainTexCol = tex2D(_GradientTex, (0.0, gradT));
- const fixed4 altTexCol = tex2D(_AltGradientTex, (0.0, gradT));
- const float t = _Time.y;
- const float function = (cos(t) + 1) / 2;
- const float lerpT = clamp(function, 0, 1);
- col = lerp(mainTexCol, altTexCol, lerpT);
- col.a *= _AlphaMultiplier;
- return col;
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement