From abe231126d2601ec8c61536e4cb9149cb999913f Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Mon, 14 Oct 2024 16:36:52 -0700 Subject: [PATCH] Display: restore intersection and cusp highlighting This increases resource use a bit, because we now have to hold two fragments in memory at once instead of just one. It's still much better than holding all of the top twelve fragments, though! --- app-proto/full-interface/src/inversive.frag | 33 ++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) 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