diff --git a/renderer/lights.lisp b/renderer/lights.lisp index 543a2a7a..ba067aef 100644 --- a/renderer/lights.lisp +++ b/renderer/lights.lisp @@ -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) @@ -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) @@ -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 diff --git a/renderer/shadow-map.lisp b/renderer/shadow-map.lisp index 0dd0366d..858e3f8a 100644 --- a/renderer/shadow-map.lisp +++ b/renderer/shadow-map.lisp @@ -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))