t1 / TFDContents / Assets / Resources / DepthShader.shader @ 9
이력 | 보기 | 이력해설 | 다운로드 (2.24 KB)
1 |
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' |
---|---|
2 |
|
3 |
Shader "Kinect/DepthShader" { |
4 |
Properties { |
5 |
_MainTex ("Base (RGB)", 2D) = "black" {} |
6 |
} |
7 |
|
8 |
SubShader { |
9 |
Pass { |
10 |
ZTest Always Cull Off ZWrite Off |
11 |
Fog { Mode off } |
12 |
|
13 |
CGPROGRAM |
14 |
#pragma target 5.0 |
15 |
//#pragma enable_d3d11_debug_symbols |
16 |
|
17 |
#pragma vertex vert |
18 |
#pragma fragment frag |
19 |
|
20 |
#include "UnityCG.cginc" |
21 |
|
22 |
uniform sampler2D _MainTex; |
23 |
uniform float _TexResX; |
24 |
uniform float _TexResY; |
25 |
uniform float _TotalPoints; |
26 |
uniform int _FirstUserIndex; |
27 |
|
28 |
StructuredBuffer<float> _DepthBuffer; |
29 |
StructuredBuffer<float> _HistBuffer; |
30 |
StructuredBuffer<float> _BodyIndexBuffer; |
31 |
|
32 |
struct v2f { |
33 |
float4 pos : SV_POSITION; |
34 |
float2 uv : TEXCOORD0; |
35 |
}; |
36 |
|
37 |
v2f vert (appdata_base v) |
38 |
{ |
39 |
v2f o; |
40 |
|
41 |
o.pos = UnityObjectToClipPos (v.vertex); |
42 |
o.uv = v.texcoord; |
43 |
|
44 |
return o; |
45 |
} |
46 |
|
47 |
float4 frag (v2f i) : COLOR |
48 |
{ |
49 |
int dx = (int)(i.uv.x * _TexResX); |
50 |
int dy = (int)(i.uv.y * _TexResY); |
51 |
int di = (int)(dx + dy * _TexResX); |
52 |
|
53 |
//float player = tex2D(_MainTex, i.uv).w; |
54 |
//int playerIndex = (int)(player * 255); |
55 |
|
56 |
float playerIndex = (int)_BodyIndexBuffer[di]; |
57 |
|
58 |
//if (player != 0) |
59 |
if (playerIndex != 255) |
60 |
{ |
61 |
int depth = (int)_DepthBuffer[di]; |
62 |
float hist = 1 - (_HistBuffer[depth] / _TotalPoints); |
63 |
|
64 |
if((playerIndex % 8) == _FirstUserIndex) |
65 |
{ |
66 |
return float4(hist, hist, 0, 1); // yellow |
67 |
} |
68 |
else |
69 |
{ |
70 |
switch(playerIndex % 4) |
71 |
{ |
72 |
case 0: |
73 |
return float4(hist, 0, 0, 0.9); // red |
74 |
case 1: |
75 |
return float4(0, hist, 0, 0.9); // green |
76 |
case 2: |
77 |
return float4(0, 0, hist, 0.9); // blue |
78 |
case 3: |
79 |
return float4(hist, 0, hist, 0.9); // magenta |
80 |
} |
81 |
} |
82 |
|
83 |
return float4(hist, hist, hist, 1); // white |
84 |
} |
85 |
// else |
86 |
// { |
87 |
// float depth = _DepthBuffer[di]; |
88 |
// if(depth == 0) depth = 5000; |
89 |
// float hist = 1 - depth / 5000; |
90 |
// |
91 |
// return float4(hist, hist, hist, 1); // gray |
92 |
// } |
93 |
|
94 |
return float4(0, 0, 0, 0); // invisible |
95 |
} |
96 |
|
97 |
ENDCG |
98 |
} |
99 |
} |
100 |
|
101 |
Fallback Off |
102 |
} |