Skip to content

Commit

Permalink
Kludge to make multi-materials work
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jul 17, 2023
1 parent a7fd7f3 commit a5ae931
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 15 additions & 8 deletions renderer/standard-renderer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,24 @@
(loop for material across (materials renderable)
do (stage material area)))

(defmethod render-with :before ((pass standard-render-pass) (object per-array-material-renderable) program)
(prepare-pass-program pass program)
;; FIXME: this is NOT correct, as only the last material will truly be in effect.
;; need to somehow be able to call RENDER-WITH on the pass and program within the RENDER???
(loop for material across (materials object)
do (render-with pass material program)))
(defmethod render-with :before ((pass standard-render-pass) (renderable per-array-material-renderable) program)
(prepare-pass-program pass program))

(defmethod render-with ((pass standard-render-pass) (renderable per-array-material-renderable) program)
;; KLUDGE: we can't do this in RENDER as we don't have access to the PASS variable, which we
;; need to set the per-vao material. This will break user expectations, as the RENDER
;; primary on the renderable is not invoked. Not sure how to fix this issue.
(setf (uniform program "model_matrix") (model-matrix))
(setf (uniform program "inv_model_matrix") (minv (model-matrix)))
(loop for vao across (vertex-arrays renderable)
for material across (materials renderable)
do (render-with pass material program)
(render vao program)))

(defmethod (setf mesh) :after ((meshes cons) (object per-array-material-renderable))
(defmethod (setf mesh) :after ((meshes cons) (renderable per-array-material-renderable))
(let ((arrays (make-array (length meshes))))
(map-into arrays #'material meshes)
(setf (materials object) arrays)))
(setf (materials renderable) arrays)))

(define-shader-pass light-cache-render-pass (standard-render-pass)
((light-cache :initform (org.shirakumo.fraf.trial.space.kd-tree:make-kd-tree) :reader light-cache)
Expand Down
7 changes: 5 additions & 2 deletions shader-pass.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -403,20 +403,23 @@
(loop for (object . program) across frame
do (render-with pass object program)))

(defmethod render-with ((pass per-object-pass) object program)
(defmethod render-with :around ((pass per-object-pass) (object renderable) (program shader-program))
(restart-case
(progn
(prepare-pass-program pass program)
(with-pushed-matrix ()
(apply-transforms object)
(bind-textures object)
(update-uniforms object program)
(render object program)))
(call-next-method)))
#-kandria-release
(leave ()
:report "Leave the object"
(leave object T))))

(defmethod render-with ((pass shader-pass) object program)
(render object program))

(define-shader-pass single-shader-pass ()
((shader-program :accessor shader-program)))

Expand Down

0 comments on commit a5ae931

Please sign in to comment.