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 5645bcf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion trial.asd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(:file "asset-pool" :depends-on ("package" "asset"))
(:file "async" :depends-on ("package"))
(:file "bag" :depends-on ("package" "container"))
(:file "camera" :depends-on ("package" "container" "input" "transforms" "helpers"))
(:file "camera" :depends-on ("package" "container" "input" "transforms" "helpers" "global-bounds-cache"))
(:file "capture" :depends-on ("package" "toolkit" "serialize" "event-loop" "input"))
(:file "command-line" :depends-on ("package" "toolkit"))
(:file "conditions" :depends-on ("package"))
Expand Down

0 comments on commit 5645bcf

Please sign in to comment.