diff --git a/app-proto/full-interface/src/inversive.frag b/app-proto/full-interface/src/inversive.frag index 339be00..d50cb1e 100644 --- a/app-proto/full-interface/src/inversive.frag +++ b/app-proto/full-interface/src/inversive.frag @@ -191,19 +191,44 @@ void main() { // composite the sphere fragments vec3 color = vec3(0.); int layer = layer_cnt - 1; - TaggedDepth hit; + TaggedDepth hit = top_hits[layer]; + Fragment frag_next = sphere_shading( + sphere_list[hit.id], + hit.depth * dir, + hit.dimming * color_list[hit.id] + ); + float highlight_next = highlight_list[hit.id]; + --layer; for (; layer >= layer_threshold; --layer) { - // shade the current fragment + // load the current fragment + Fragment frag = frag_next; + float highlight = highlight_next; + + // shade the next fragment hit = top_hits[layer]; - Fragment frag = sphere_shading( + frag_next = sphere_shading( sphere_list[hit.id], hit.depth * dir, hit.dimming * color_list[hit.id] ); - float highlight = highlight_list[hit.id]; + highlight_next = highlight_list[hit.id]; + + // highlight intersections + float ixn_dist = intersection_dist(frag, frag_next); + float max_highlight = max(highlight, highlight_next); + float ixn_highlight = 0.5 * max_highlight * (1. - smoothstep(2./3.*ixn_threshold, 1.5*ixn_threshold, ixn_dist)); + frag.color = mix(frag.color, vec4(1.), ixn_highlight); + frag_next.color = mix(frag_next.color, vec4(1.), ixn_highlight); + + // highlight cusps + float cusp_cos = abs(dot(dir, frag.normal)); + float cusp_threshold = 2.*sqrt(ixn_threshold * sphere_list[hit.id].lt.s); + float cusp_highlight = highlight * (1. - smoothstep(2./3.*cusp_threshold, 1.5*cusp_threshold, cusp_cos)); + frag.color = mix(frag.color, vec4(1.), cusp_highlight); // composite the current fragment color = mix(color, frag.color.rgb, frag.color.a); } + color = mix(color, frag_next.color.rgb, frag_next.color.a); outColor = vec4(sRGB(color), 1.); } \ No newline at end of file