enable camera frustum culling for bsp rendering

This commit is contained in:
asrael 2025-11-10 10:24:27 -06:00
parent 704b14b2a0
commit ac8ab8d60d
No known key found for this signature in database
GPG key ID: 2786557804DFAE24
4 changed files with 36 additions and 82 deletions

View file

@ -1,53 +0,0 @@
(local pxl8 (require :pxl8))
(var camera-angle 0)
(local camera-height 0)
(local camera-distance 450)
(var fps 0)
(var world nil)
(fn init []
(set world (pxl8.world_new))
(let [result (pxl8.world_load world "res/maps/test.bsp")]
(if (< result 0)
(pxl8.error (.. "Failed to load test.bsp - result: " result))
(pxl8.info "Loaded world successfully!"))))
(fn update [dt]
(when (> dt 0)
(set fps (math.floor (/ 1.0 dt))))
(when (pxl8.world_is_loaded world)
(set camera-angle (+ camera-angle (* dt 0.5)))))
(fn frame []
(pxl8.clr 0)
(pxl8.text (.. "FPS: " fps) 10 40 14)
(if (pxl8.world_is_loaded world)
(let [cam-x (* camera-distance (math.cos camera-angle))
cam-z (* camera-distance (math.sin camera-angle))]
(pxl8.text (.. "Camera: " (string.format "%.0f" cam-x) ","
(string.format "%.0f" camera-height) ","
(string.format "%.0f" cam-z)) 10 55 12)
(pxl8.clear_zbuffer)
(pxl8.set_backface_culling true)
(pxl8.set_wireframe true)
(let [aspect (/ (pxl8.get_width) (pxl8.get_height))
fov 1.047]
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 1.0 4096.0)))
(pxl8.set_view (pxl8.mat4_lookat
[cam-x camera-height cam-z]
[0 0 0]
[0 1 0]))
(pxl8.set_model (pxl8.mat4_identity))
(pxl8.world_render world [cam-x camera-height cam-z]))))
{:init init
:update update
:frame frame}

View file

@ -114,10 +114,6 @@
target-y (+ eye-y (math.sin cam-pitch))
target-z (+ cam-z forward-z)]
(pxl8.text (.. "Pos: " (string.format "%.0f" cam-x) ","
(string.format "%.0f" cam-y) ","
(string.format "%.0f" cam-z)) 10 25 12)
(pxl8.clear_zbuffer)
(pxl8.set_backface_culling true)
(pxl8.set_wireframe false)
@ -134,7 +130,11 @@
(pxl8.set_model (pxl8.mat4_identity))
(pxl8.set_affine_textures affine)
(pxl8.world_render world [cam-x eye-y cam-z]))
(pxl8.world_render world [cam-x eye-y cam-z])
(pxl8.text (.. "Pos: " (string.format "%.0f" cam-x) ","
(string.format "%.0f" cam-y) ","
(string.format "%.0f" cam-z)) 10 25 12))
(let [new-state (debug-ui.render {:show-debug-ui show-debug-ui
:fps fps