From e738b4d3c5866982ff78fadf80b1d0935d7bdf35 Mon Sep 17 00:00:00 2001
From: httpdigest <kburjack@googlemail.com>
Date: Thu, 4 Jan 2024 14:22:49 +0100
Subject: [PATCH] Use ARB_conservative_depth when available

and discard fragment when ray does not intersect voxels.
---
 res/org/lwjgl/demo/opengl/shader/raymarching.fs.glsl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/res/org/lwjgl/demo/opengl/shader/raymarching.fs.glsl b/res/org/lwjgl/demo/opengl/shader/raymarching.fs.glsl
index 922288e3..d4640cd7 100644
--- a/res/org/lwjgl/demo/opengl/shader/raymarching.fs.glsl
+++ b/res/org/lwjgl/demo/opengl/shader/raymarching.fs.glsl
@@ -5,6 +5,10 @@
 #version 330 core
 
 layout (location = 0) out vec4 fragColor;
+#ifdef GL_ARB_conservative_depth
+#extension GL_ARB_conservative_depth : enable
+layout (depth_less) out float gl_FragDepth;
+#endif
 
 uniform sampler3D tex;
 uniform mat4 mvp;
@@ -31,8 +35,7 @@ vec3 rayMarch(vec3 o, vec3 d, vec3 ts) {
       break;
     }
   }
-  gl_FragDepth = 1.0-1e-6;
-  return vec3(i)/vec3(N);
+  discard;
 }
 
 void main(void) {