-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstereoscopic.fxsub
50 lines (42 loc) · 1.65 KB
/
stereoscopic.fxsub
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
50
float4 ComputeStereoCoord(sampler depth, float2 coord, float maxSeparation, float ZPD)
{
const float samples[3] = { 0.5f, 0.66f, 1.0f };
float minDepthL = 1;
float minDepthR = 1;
float2 uv = 0;
for (int i = 0; i < 3; ++ i)
{
uv.x = samples[i] * maxSeparation;
minDepthL = min(minDepthL, tex2Dlod(depth, float4(coord + uv, 0, 0)).r);
minDepthR = min(minDepthR, tex2Dlod(depth, float4(coord - uv, 0, 0)).r);
}
float parallaxL = maxSeparation * (1 - ZPD / minDepthL);
float parallaxR = maxSeparation * (1 - ZPD / minDepthR);
return float4(coord + float2(parallaxL, 0), coord - float2(parallaxR, 0));
}
float4 StereoscopicPS(float2 tex : TEXCOORD0, uniform sampler source, uniform sampler depth) : COLOR
{
#if POST_STEREOSCOPIC_MODE == 4
float2 coord = tex.x < 0.5 ? tex * float2(2,1) : float2((tex.x - 0.5f) * 2, tex.y);
#elif POST_STEREOSCOPIC_MODE == 5
float2 coord = tex.y < 0.5 ? tex * float2(1,2) : float2(tex.x, (tex.y - 0.5f) * 2);
#else
float2 coord = tex;
#endif
float4 stereo = ComputeStereoCoord(depth, coord, 0.01, 0.3);
float3 left = tex2Dlod(source, float4(stereo.xy, 0, 0)).rgb;
float3 right = tex2Dlod(source, float4(stereo.zw, 0, 0)).rgb;
#if POST_STEREOSCOPIC_MODE == 1 // RedGreen
return float4(float3(right.r, left.gb), 1);
#elif POST_STEREOSCOPIC_MODE == 2 // YellowBlue
return float4(float3(left.rg, right.b), 1);
#elif POST_STEREOSCOPIC_MODE == 3 // RedCyan
return float4(dot(left.gb, float2(0.7f, 0.3f)), right.rg, 1);
#elif POST_STEREOSCOPIC_MODE == 4 // Horizontal
return float4(tex.x < 0.5 ? left : right, 1);
#elif POST_STEREOSCOPIC_MODE == 5 // Vertical
return float4(tex.y < 0.5 ? left : right, 1);
#else
return stereo;
#endif
}