Mercurial > hg > Game > Games
comparison Orchestland/Assets/LeapMotion/Resources/LeapCG.cginc @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 #include "UnityCG.cginc" | |
2 | |
3 /////////////// Constants for Dragonfly Color Correction /////////////// | |
4 #define CAMERA_WIDTH 608.0 | |
5 #define CAMERA_HEIGHT 540.0 | |
6 #define CAMERA_DELTA float2(1.0 / CAMERA_WIDTH, 1.0 / CAMERA_HEIGHT) | |
7 | |
8 #define RGB_SCALE 1.5 * float3(1.5, 1.0, 0.5) | |
9 | |
10 #define R_OFFSET CAMERA_DELTA * float2(-0.5, 0.0) | |
11 #define G_OFFSET CAMERA_DELTA * float2(-0.5, 0.5) | |
12 #define B_OFFSET CAMERA_DELTA * float2( 0.0, 0.5) | |
13 | |
14 #define TRANSFORMATION transpose(float4x4(5.0670, -1.2312, 0.8625, -0.0507, -1.5210, 3.1104, -2.0194, 0.0017, -0.8310, -0.3000, 13.1744, -0.1052, -2.4540, -1.3848, -10.9618, 1.0000)) | |
15 #define CONSERVATIVE transpose(float4x4(5.0670, 0.0000, 0.8625, 0.0000, 0.0000, 3.1104, 0.0000, 0.0017, 0.0000, 0.0000, 13.1744, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000)) | |
16 | |
17 #define FUDGE_THRESHOLD 0.5 | |
18 #define FUDGE_CONSTANT (1 / (1 - FUDGE_THRESHOLD)) | |
19 //////////////////////////////////////////////////////////////////////// | |
20 | |
21 sampler2D _LeapTexture; | |
22 sampler2D _LeapDistortion; | |
23 | |
24 float4 _LeapProjection; | |
25 float _LeapGammaCorrectionExponent; | |
26 | |
27 float2 LeapGetUndistortedUV(float4 screenPos){ | |
28 float2 uv = (screenPos.xy / screenPos.w) * 2 - float2(1,1); | |
29 float2 tangent = (uv + _LeapProjection.xy) / _LeapProjection.zw; | |
30 float2 distortionUV = 0.125 * tangent + float2(0.5, 0.5); | |
31 | |
32 float4 distortionAmount = tex2D(_LeapDistortion, distortionUV); | |
33 return float2(DecodeFloatRG(distortionAmount.xy), DecodeFloatRG(distortionAmount.zw)) * 2.3 - float2(0.6, 0.6); | |
34 } | |
35 | |
36 float LeapRawBrightnessUV(float2 uv){ | |
37 #if LEAP_FORMAT_IR | |
38 return tex2D(_LeapTexture, uv).a; | |
39 #else | |
40 return pow(dot(tex2D(_LeapTexture, uv), float4(1, -0.105, -0.05, -0.001)), 0.5); | |
41 #endif | |
42 } | |
43 | |
44 float3 LeapRawColorUV(float2 uv){ | |
45 #if LEAP_FORMAT_IR | |
46 float brightness = LeapRawBrightnessUV(uv); | |
47 return float3(brightness, brightness, brightness); | |
48 #else | |
49 float4 input_lf; | |
50 | |
51 input_lf.a = tex2D(_LeapTexture, uv).a; | |
52 input_lf.r = tex2D(_LeapTexture, uv + R_OFFSET).b; | |
53 input_lf.g = tex2D(_LeapTexture, uv + G_OFFSET).r; | |
54 input_lf.b = tex2D(_LeapTexture, uv + B_OFFSET).g; | |
55 | |
56 float4 output_lf = mul(TRANSFORMATION, input_lf); | |
57 float4 output_lf_fudge = mul(CONSERVATIVE, input_lf); | |
58 | |
59 float3 fudgeMult = input_lf.rgb * FUDGE_CONSTANT - FUDGE_CONSTANT * FUDGE_THRESHOLD; | |
60 float3 fudge = step(FUDGE_THRESHOLD, input_lf.rgb) * fudgeMult; | |
61 | |
62 float3 color = (output_lf_fudge.rgb - output_lf.rgb) * fudge * fudge + output_lf.rgb; | |
63 | |
64 return saturate(color * RGB_SCALE); | |
65 #endif | |
66 } | |
67 | |
68 float4 LeapRawColorBrightnessUV(float2 uv){ | |
69 #if LEAP_FORMAT_IR | |
70 float brightness = LeapRawBrightnessUV(uv); | |
71 return float4(brightness, brightness, brightness, brightness); | |
72 #else | |
73 float4 input_lf; | |
74 | |
75 input_lf.a = tex2D(_LeapTexture, uv).a; | |
76 input_lf.r = tex2D(_LeapTexture, uv + R_OFFSET).b; | |
77 input_lf.g = tex2D(_LeapTexture, uv + G_OFFSET).r; | |
78 input_lf.b = tex2D(_LeapTexture, uv + B_OFFSET).g; | |
79 | |
80 float4 output_lf = mul(TRANSFORMATION, input_lf); | |
81 float4 output_lf_fudge = mul(CONSERVATIVE, input_lf); | |
82 | |
83 float3 fudgeMult = input_lf.rgb * FUDGE_CONSTANT - FUDGE_CONSTANT * FUDGE_THRESHOLD; | |
84 float3 fudge = step(FUDGE_THRESHOLD, input_lf.rgb) * fudgeMult; | |
85 | |
86 float3 color = (output_lf_fudge.rgb - output_lf.rgb) * fudge * fudge + output_lf.rgb; | |
87 | |
88 return saturate(float4(color * RGB_SCALE, pow(dot(input_lf, float4(-0.051, -0.001, -0.105, 1)), 0.5))); | |
89 #endif | |
90 } | |
91 | |
92 float LeapRawBrightness(float4 screenPos){ | |
93 return LeapRawBrightnessUV(LeapGetUndistortedUV(screenPos)); | |
94 } | |
95 | |
96 float3 LeapRawColor(float4 screenPos){ | |
97 return LeapRawColorUV(LeapGetUndistortedUV(screenPos)); | |
98 } | |
99 | |
100 float4 LeapRawColorBrightness(float4 screenPos){ | |
101 return LeapRawColorBrightnessUV(LeapGetUndistortedUV(screenPos)); | |
102 } | |
103 | |
104 float LeapBrightnessUV(float2 uv){ | |
105 return pow(LeapRawBrightnessUV(uv), _LeapGammaCorrectionExponent); | |
106 } | |
107 | |
108 float3 LeapColorUV(float2 uv){ | |
109 return pow(LeapRawColorUV(uv), _LeapGammaCorrectionExponent); | |
110 } | |
111 | |
112 float4 LeapColorBrightnessUV(float2 uv){ | |
113 return pow(LeapRawColorBrightnessUV(uv), _LeapGammaCorrectionExponent); | |
114 } | |
115 | |
116 float LeapBrightness(float4 screenPos){ | |
117 return pow(LeapRawBrightness(screenPos), _LeapGammaCorrectionExponent); | |
118 } | |
119 | |
120 float3 LeapColor(float4 screenPos){ | |
121 return pow(LeapRawColor(screenPos), _LeapGammaCorrectionExponent); | |
122 } | |
123 | |
124 float4 LeapColorBrightness(float4 screenPos){ | |
125 return pow(LeapRawColorBrightness(screenPos), _LeapGammaCorrectionExponent); | |
126 } |