Skip to content

Commit

Permalink
Idk.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Dec 14, 2024
1 parent 3fe007a commit 3a40ad5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
21 changes: 21 additions & 0 deletions renderer/lights.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
(setf (light-type target) 2)
(when (shadow-map light) (setf (shadow-map target) (shadow-map light))))

(defmethod compute-shadow-matrix ((light point-light) camera matrix))

;; TODO: Implement IN-VIEW-P for spot-light

(defclass directional-light (light)
Expand Down Expand Up @@ -116,6 +118,15 @@
most-positive-single-float
most-positive-single-float))

(defmethod compute-shadow-matrix ((light directional-light) camera matrix)
(let ((point (focal-point camera))
(orientation (quat)))
(declare (dynamic-extent orientation))
(global-orientation light orientation)
(!m* matrix
(nmortho matrix -50.0 +50.0 -50.0 +50.0 1.0 200.0)
(mlookat (nv+ (v* (q* orientation (direction light)) -100) point) point +vy3+))))

;; TODO: Implement IN-VIEW-P for directional-light

(defclass spot-light (directional-light located-light)
Expand Down Expand Up @@ -158,4 +169,14 @@
(setf (target light) (global-location entity))
entity)

(defmethod compute-shadow-matrix ((light spot-light) camera matrix)
(let ((location (vec3))
(orientation (quat)))
(declare (dynamic-extent location orientation))
(global-location light location)
(global-orientation light orientation)
(!m* matrix
(nmperspective matrix (* 2.0 (outer-radius light)) 1.0 1.0 1000.0)
(mlookat location (v+ location (q* orientation (direction light))) +vy3+))))

;; TODO: Implement IN-VIEW-P for spot-light
25 changes: 5 additions & 20 deletions renderer/shadow-map.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,11 @@

(defmethod <- progn ((struct shadow-map-info) (light light))
(setf (sample-count struct) 4)
(setf (sample-spread struct) 0.0002))

(defmethod <- progn ((struct shadow-map-info) (light directional-light))
(let ((point (focal-point (camera (scene +main+))))
(orientation (quat)))
(declare (dynamic-extent orientation))
(global-orientation light orientation)
(setf (slot-value struct 'projection-matrix)
(n*m (mortho -50.0 +50.0 -50.0 +50.0 1.0 200.0)
(mlookat (nv+ (v* (q* orientation (direction light)) -100) point) point +vy3+)))))

(defmethod <- progn ((struct shadow-map-info) (light spot-light))
(let ((location (vec3))
(orientation (quat)))
(declare (dynamic-extent location orientation))
(global-location light location)
(global-orientation light orientation)
(setf (slot-value struct 'projection-matrix)
(n*m (mperspective (* 2.0 (outer-radius light)) 1.0 1.0 1000.0)
(mlookat location (v+ location (q* orientation (direction light))) +vy3+)))))
(setf (sample-spread struct) 0.0002)
(let ((m (mat4)))
(declare (dynamic-extent m))
(compute-shadow-matrix light (camera (scene +main+)) m)
(setf (slot-value struct 'projection-matrix) m)))

(defmethod <- progn ((struct shadow-map-info) (light point-light))
(setf (far-plane struct) 1000.0))
Expand Down

0 comments on commit 3a40ad5

Please # to comment.