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.
This commit is contained in:
Aaron Fenyes 2024-08-28 01:50:17 -07:00
parent c04e29f586
commit 3d7ee98dd6

View File

@ -40,7 +40,7 @@ uniform vec2 radius;
uniform float opacity; uniform float opacity;
uniform float highlight; uniform float highlight;
uniform int layer_threshold; uniform int layer_threshold;
uniform bool test_mode; uniform bool debug_mode;
// light and camera // light and camera
const float focal_slope = 0.3; 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 // sort the fragments by depth, using an insertion sort
for (int take = 1; take < frag_cnt; ++take) { for (int take = 1; take < frag_cnt; ++take) {
taggedFrag pulled = frags[take]; taggedFrag pulled = frags[take];