-
Notifications
You must be signed in to change notification settings - Fork 2
/
reflection.glsl
36 lines (32 loc) · 984 Bytes
/
reflection.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
vec4 marchRef (in vec3 rayOrigin, in vec3 rayDirection, in float deltaT) {
float t = 0.;
float maxI = 0.;
float trap = maxDistance;
for (int i = 0; i < maxSteps / 3; i++) {
vec3 d = map(rayOrigin + rayDirection * t, deltaT);
if (d.x < epsilon) return vec4(t + d.x, d.y, float(i), d.z);
t += d.x;
maxI = float(i);
trap = d.z;
if (t > maxDistance) break;
}
return vec4(-1., 0., maxI, trap);
}
vec3 reflection (in vec3 ro, in vec3 rd, in float deltaT) {
rd = normalize(rd);
vec4 t = marchRef(ro + rd * .01, rd, deltaT);
vec3 pos = ro + rd * t.x;
vec3 color = vec3(0.);
if (t.x > 0.) {
vec3 nor = getNormal(pos, .0001, deltaT);
color = diffuseColor(pos, nor, rd, t.y, t.w, deltaT);
color /= max(1.0, pow(t.x, 1.0));
} else {
color = vec3(0.125); // 0.6 * vec3(getBackground(pos.xy));
}
return color;
}
vec3 reflection (in vec3 ro, in vec3 rd) {
return reflection(ro, rd, 0.);
}
#pragma glslify: export(reflection)