Application prototype #14
@ -121,29 +121,31 @@ vec2 sphere_cast(vecInv v, vec3 dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
const int sphere_cnt = 2;
|
||||||
|
|
||||||
vec2 scr = (2.*gl_FragCoord.xy - resolution) / shortdim;
|
vec2 scr = (2.*gl_FragCoord.xy - resolution) / shortdim;
|
||||||
vec3 dir = vec3(focal_slope * scr, -1.);
|
vec3 dir = vec3(focal_slope * scr, -1.);
|
||||||
|
|
||||||
// initialize two spheres
|
// initialize two spheres
|
||||||
vecInv v [2];
|
vecInv sphere_list [sphere_cnt];
|
||||||
v[0] = sphere(vec3(0.5, 0.5, -5. + ctrl.x), radius.x);
|
sphere_list[0] = sphere(vec3(0.5, 0.5, -5. + ctrl.x), radius.x);
|
||||||
v[1] = sphere(vec3(-0.5, -0.5, -5. + ctrl.y), radius.y);
|
sphere_list[1] = sphere(vec3(-0.5, -0.5, -5. + ctrl.y), radius.y);
|
||||||
vec3 color0 = vec3(1., 0.214, 0.);
|
vec3 color_list [sphere_cnt];
|
||||||
vec3 color1 = vec3(0., 0.214, 1.);
|
color_list[0] = vec3(1., 0.214, 0.);
|
||||||
|
color_list[1] = vec3(0., 0.214, 1.);
|
||||||
|
|
||||||
// cast rays through the spheres
|
// cast rays through the spheres
|
||||||
vec2 u0 = sphere_cast(v[0], dir);
|
vec2 depth_pairs [sphere_cnt];
|
||||||
vec2 u1 = sphere_cast(v[1], dir);
|
taggedFrag frags [2*sphere_cnt];
|
||||||
|
for (int i = 0; i < sphere_cnt; i++) {
|
||||||
|
vec2 hit_depths = sphere_cast(sphere_list[i], dir);
|
||||||
|
frags[2*i] = sphere_shading(sphere_list[i], hit_depths[0] * dir, color_list[i], i);
|
||||||
|
frags[2*i+1] = sphere_shading(sphere_list[i], hit_depths[1] * dir, color_list[i], i);
|
||||||
|
}
|
||||||
|
|
||||||
// shade and depth-sort the impact points
|
// shade and depth-sort the impact points
|
||||||
taggedFrag front_hits[2] = sort(
|
taggedFrag front_hits[2] = sort(frags[0], frags[2]);
|
||||||
sphere_shading(v[0], u0[0] * dir, color0, 0),
|
taggedFrag back_hits[2] = sort(frags[1], frags[3]);
|
||||||
sphere_shading(v[1], u1[0] * dir, color1, 1)
|
|
||||||
);
|
|
||||||
taggedFrag back_hits[2] = sort(
|
|
||||||
sphere_shading(v[0], u0[1] * dir, color0, 0),
|
|
||||||
sphere_shading(v[1], u1[1] * dir, color1, 1)
|
|
||||||
);
|
|
||||||
taggedFrag middle_frags[2] = sort(front_hits[1], back_hits[0]);
|
taggedFrag middle_frags[2] = sort(front_hits[1], back_hits[0]);
|
||||||
|
|
||||||
// finish depth sorting
|
// finish depth sorting
|
||||||
@ -170,7 +172,7 @@ void main() {
|
|||||||
|
|
||||||
// cusps
|
// cusps
|
||||||
float cusp_cos = abs(dot(dir, frag0.normal));
|
float cusp_cos = abs(dot(dir, frag0.normal));
|
||||||
float cusp_threshold = 2.*sqrt(ixn_threshold * v[frag0.id].lt.s);
|
float cusp_threshold = 2.*sqrt(ixn_threshold * sphere_list[frag0.id].lt.s);
|
||||||
float cusp_highlight = highlight * (1. - smoothstep(2./3.*cusp_threshold, 1.5*cusp_threshold, cusp_cos));
|
float cusp_highlight = highlight * (1. - smoothstep(2./3.*cusp_threshold, 1.5*cusp_threshold, cusp_cos));
|
||||||
frags_by_depth[i].color = mix(frags_by_depth[i].color, vec4(1.), cusp_highlight);
|
frags_by_depth[i].color = mix(frags_by_depth[i].color, vec4(1.), cusp_highlight);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user