From 3d7ee98dd64267cb00732079f5a51b45d5e900f2 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Wed, 28 Aug 2024 01:50:17 -0700 Subject: [PATCH] Ray-caster: check layer count In debug mode, show the layer count instead of the shaded image. This reveals a bug: testing whether the hit depth is NaN doesn't actually detect sphere misses, because `sphere_cast` returns -1 rather than NaN to indicate a miss. --- app-proto/inversive-display/src/inversive.frag | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app-proto/inversive-display/src/inversive.frag b/app-proto/inversive-display/src/inversive.frag index ce6deae..5620210 100644 --- a/app-proto/inversive-display/src/inversive.frag +++ b/app-proto/inversive-display/src/inversive.frag @@ -40,7 +40,7 @@ uniform vec2 radius; uniform float opacity; uniform float highlight; uniform int layer_threshold; -uniform bool test_mode; +uniform bool debug_mode; // light and camera const float focal_slope = 0.3; @@ -151,6 +151,19 @@ void main() { } } + /* DEBUG */ + // in debug mode, show the layer count instead of the shaded image + if (debug_mode) { + // at the bottom of the screen, show the color scale instead of the + // layer count + if (gl_FragCoord.y < 10.) frag_cnt = int(8. * gl_FragCoord.x / resolution.x); + + // convert number to color + ivec3 bits = frag_cnt / ivec3(1, 2, 4); + outColor = vec4(mod(vec3(bits), 2.), 1.); + return; + } + // sort the fragments by depth, using an insertion sort for (int take = 1; take < frag_cnt; ++take) { taggedFrag pulled = frags[take];