1 Shader "Hidden/PostProcessing/Editor/Trackball"
5 #include "UnityCG.cginc"
7 #define PI 3.14159265359
8 #define PI2 6.28318530718
12 float2 _Resolution; // x: size, y: size / 2
14 float3 HsvToRgb(float3 c)
16 float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
17 float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
18 return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
21 float4 CreateWheel(v2f_img i, float crossColor, float offsetColor)
23 const float kHueOuterRadius = 0.45;
24 const float kHueInnerRadius = 0.38;
25 const float kLumOuterRadius = 0.495;
26 const float kLumInnerRadius = 0.48;
28 float4 color = (0.0).xxxx;
29 float2 uvc = i.uv - (0.5).xx;
30 float dist = sqrt(dot(uvc, uvc));
31 float delta = fwidth(dist);
32 float angle = atan2(uvc.x, uvc.y);
36 float radius = (0.5 - kHueInnerRadius) * _Resolution.x + 1.0;
37 float2 pixel = (_Resolution.xx - 1.0) * i.uv + 1.0;
39 float vline = step(floor(fmod(pixel.x, _Resolution.y)), 0.0);
40 vline *= step(radius, pixel.y) * step(pixel.y, _Resolution.x - radius);
42 float hline = step(floor(fmod(pixel.y, _Resolution.y)), 0.0);
43 hline *= step(radius, pixel.x) * step(pixel.x, _Resolution.x - radius);
45 color += hline.xxxx * (1.0).xxxx;
46 color += vline.xxxx * (1.0).xxxx;
47 color = saturate(color);
48 color *= half4((crossColor).xxx, 0.05);
53 float alphaOut = smoothstep(kHueOuterRadius - delta, kHueOuterRadius + delta, dist);
54 float alphaIn = smoothstep(kHueInnerRadius - delta, kHueInnerRadius + delta, dist);
57 hue = 1.0 - ((hue > 0.0) ? hue : PI2 + hue) / PI2;
58 float4 c = float4(HsvToRgb(float3(hue, 1.0, 1.0)), 1.0);
59 color += lerp((0.0).xxxx, c, alphaIn - alphaOut);
64 float alphaOut = smoothstep(kLumOuterRadius - delta, kLumOuterRadius + delta, dist);
65 float alphaIn = smoothstep(kLumInnerRadius - delta, kLumInnerRadius + delta / 2, dist);
66 float4 c = float4((offsetColor).xxx, 1.0);
68 float a = PI * _Offset;
69 if (_Offset >= 0 && angle < a && angle > 0.0)
70 c = float4((1.0).xxx, 0.5);
71 else if (angle > a && angle < 0.0)
72 c = float4((1.0).xxx, 0.5);
74 color += lerp((0.0).xxxx, c, alphaIn - alphaOut);
77 return color * _DisabledState;
80 float4 FragTrackballDark(v2f_img i) : SV_Target
82 return CreateWheel(i, 1.0, 0.15);
85 float4 FragTrackballLight(v2f_img i) : SV_Target
87 return CreateWheel(i, 0.0, 0.3);
94 Cull Off ZWrite Off ZTest Always
101 #pragma vertex vert_img
102 #pragma fragment FragTrackballDark
112 #pragma vertex vert_img
113 #pragma fragment FragTrackballLight