From 799257bfdbb481c86129dfde4d46dae0131a1cc1 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Sat, 23 Jan 2021 23:49:13 -0600 Subject: [PATCH] Cull vertices beyond cull distance --- shaders/flat.frag | 5 +++++ shaders/flat.vert | 9 +++++++++ 2 files changed, 14 insertions(+) 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;