Skip to content

Commit

Permalink
frustum culling workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jul 11, 2024
1 parent 6db6e66 commit 214f92f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions examples/culling.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(in-package #:org.shirakumo.fraf.trial.examples)

(defclass culling-camera (editor-camera)
((visible-count :initform 0 :accessor visible-count)
(culled-count :initform 0 :accessor culled-count)))

(defmethod map-visible (function (camera culling-camera) (container container))
(setf (visible-count camera) 0)
(setf (culled-count camera) 0)
(do-scene-graph (object container)
(cond ((in-view-p object camera)
(incf (visible-count camera))
(funcall function object))
(T
(incf (culled-count camera))))))

(define-shader-entity basic-sphere (vertex-entity transformed-entity global-bounds-cached-entity)
((vertex-array :initform (// 'trial 'unit-sphere))))

(defmethod bsize ((_ basic-sphere)) (vec3 1))
(defmethod bradius ((_ basic-sphere)) 1f0)

(define-example culling
:title "Frustum Culling"
(enter (make-instance 'display-controller) scene)
(enter (make-instance 'culling-camera) scene)
(enter (make-instance 'render-pass) scene)
(observe! (visible-count (camera scene)) :title "Visible")
(observe! (culled-count (camera scene)) :title "Culled")
(dotimes (i 1000)
(enter (make-instance 'basic-sphere :location (vrand 0f0 1000.0)) scene)))
3 changes: 2 additions & 1 deletion examples/trial-examples.asd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
(:file "audio")
(:file "tilemap")
(:file "shader")
(:file "post-processing"))
(:file "post-processing")
(:file "culling"))
:depends-on (#-nx :trial-glfw
#+nx :trial-nxgl
:alloy-constraint
Expand Down

0 comments on commit 214f92f

Please sign in to comment.