Advertisement
VelGD

Motion Extraction - Shader Final

May 1st, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. Shader "Unlit/MotionExtractionShader"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _CurrentTex ("Current Texture", 2D) = "white" {}
  7. _DelayedTex ("Delayed Texture", 2D) = "white" {}
  8.  
  9. _GradientTex("Gradient Texture", 2D) = "white" {}
  10. _AltGradientTex("Alt Gradient Texture", 2D) = "white" {}
  11. _GradientMaxValue("Gradient Remap Max Value", Range(0, 1)) = 1.0
  12.  
  13. _AlphaMultiplier("Alpha", Range(0,1)) = 1.0
  14. }
  15. SubShader
  16. {
  17. Tags { "RenderType"="Transparent" }
  18. Blend SrcAlpha OneMinusSrcAlpha
  19.  
  20. LOD 100
  21.  
  22. Pass
  23. {
  24. CGPROGRAM
  25. #pragma vertex vert
  26. #pragma fragment frag
  27.  
  28. #include "UnityCG.cginc"
  29.  
  30. struct appdata
  31. {
  32. float4 vertex : POSITION;
  33. float2 uv : TEXCOORD0;
  34. };
  35.  
  36. struct v2f
  37. {
  38. float2 uv : TEXCOORD0;
  39. float4 vertex : SV_POSITION;
  40. };
  41.  
  42. sampler2D _CurrentTex;
  43. sampler2D _DelayedTex;
  44.  
  45. sampler2D _GradientTex;
  46. sampler2D _AltGradientTex;
  47. float _GradientMaxValue;
  48.  
  49. float _AlphaMultiplier = 1;
  50.  
  51. v2f vert (appdata v)
  52. {
  53. v2f o;
  54. o.vertex = UnityObjectToClipPos(v.vertex);
  55. o.uv = v.uv;
  56. return o;
  57. }
  58.  
  59. fixed4 frag (v2f i) : SV_Target
  60. {
  61. // sample the texture
  62. fixed4 currentColor = tex2D(_CurrentTex, i.uv);
  63. fixed4 delayedColor = tex2D(_DelayedTex, i.uv);
  64.  
  65. float delta = distance(currentColor, delayedColor);
  66.  
  67. fixed4 col;
  68. float gradT = delta / _GradientMaxValue;
  69. const fixed4 mainTexCol = tex2D(_GradientTex, (0.0, gradT));
  70. const fixed4 altTexCol = tex2D(_AltGradientTex, (0.0, gradT));
  71.  
  72. const float t = _Time.y;
  73. const float function = (cos(t) + 1) / 2;
  74. const float lerpT = clamp(function, 0, 1);
  75. col = lerp(mainTexCol, altTexCol, lerpT);
  76.  
  77. col.a *= _AlphaMultiplier;
  78.  
  79. return col;
  80. }
  81. ENDCG
  82. }
  83. }
  84. FallBack "Diffuse"
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement