-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscm_render_both_frag.glsl
40 lines (32 loc) · 1.03 KB
/
scm_render_both_frag.glsl
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
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect color0;
uniform sampler2DRect depth0;
uniform sampler2DRect color1;
uniform sampler2DRect depth1;
uniform mat4 T;
uniform int n;
uniform float t;
void main()
{
vec4 c0 = texture2DRect(color0, gl_FragCoord.xy);
vec4 d0 = texture2DRect(depth0, gl_FragCoord.xy);
vec4 c1 = texture2DRect(color1, gl_FragCoord.xy);
vec4 d1 = texture2DRect(depth1, gl_FragCoord.xy);
vec4 pn = gl_FragCoord;
vec4 p0 = T * vec4(gl_FragCoord.xy, d0.r, 1.0);
vec4 p1 = T * vec4(gl_FragCoord.xy, d1.r, 1.0);
p0 = p0 / p0.w;
p1 = p1 / p1.w;
vec4 B0 = vec4(0.0);
vec4 B1 = vec4(0.0);
for (int i = 0; i < n; i++)
{
float k = float(i) / float(n);
vec4 b0 = texture2DRect(color0, mix(pn.xy, p0.xy, k));
vec4 b1 = texture2DRect(color1, mix(pn.xy, p1.xy, k));
B0 += vec4(b0.rgb, 1.0);
B1 += vec4(b1.rgb, 1.0);
}
gl_FragColor = vec4(mix(B0.rgb / B0.a,
B1.rgb / B1.a, t), 1.0);
}