-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMotionVectorsDebug.shader
More file actions
49 lines (42 loc) · 1.11 KB
/
MotionVectorsDebug.shader
File metadata and controls
49 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Shader "MotionVectorsDebug"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_MinMax ("MinMax", Vector) = (0,0,0,0)
_MotionMultiplier ("Motion Vector Multiplier", float) = 1
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment fragMotionVectors
#include "UnityCG.cginc"
sampler2D _CameraMotionVectorsTexture;
float4 _MinMax;
float _MotionMultiplier;
// Convert a motion vector into RGBA color.
float4 VectorToColor(float2 mv)
{
float phi = atan2(mv.x, mv.y);
float hue = (phi / UNITY_PI + 1.0) * 0.5;
float r = abs(hue * 6.0 - 3.0) - 1.0;
float g = 2.0 - abs(hue * 6.0 - 2.0);
float b = 2.0 - abs(hue * 6.0 - 4.0);
float a = length(mv);
return saturate(float4(r, g, b, a));
}
fixed4 fragMotionVectors (v2f_img i) : SV_Target
{
float4 movecs = tex2D(_CameraMotionVectorsTexture, i.uv) * _MotionMultiplier;
float4 rgbMovecs = VectorToColor(movecs.rg);
return fixed4(rgbMovecs.rgb, 1);
}
ENDCG
}
}
}