diff --git a/shaders/flat.frag b/shaders/flat.frag index 9d4e267..910d6c5 100644 --- a/shaders/flat.frag +++ b/shaders/flat.frag @@ -5,6 +5,7 @@ noperspective in vec2 UV; in vec3 AMBIENT; in vec3 DIFFUSE; in vec3 SPECULAR; +flat in float kill; out vec4 FragColor; @@ -38,4 +39,8 @@ void main() { if (material.cullBack && !gl_FrontFacing) { discard; } + + if (kill == 1.0) { + discard; + } } diff --git a/shaders/flat.vert b/shaders/flat.vert index b87098a..f759746 100644 --- a/shaders/flat.vert +++ b/shaders/flat.vert @@ -15,6 +15,10 @@ out vec3 AMBIENT; out vec3 DIFFUSE; out vec3 SPECULAR; +flat out float kill; + +const float cullDistance = 100.0; + struct DirectionalLight { vec3 direction; vec3 color; @@ -43,6 +47,11 @@ uniform Material material; void main() { vec4 vertex = PROJECTION * VIEW * MODEL * vec4(pos, 1.0); gl_Position = vertex; + if (length(vertex) > cullDistance) { + kill = 1.0; + } else { + kill = 0.0; + } UV = uv;