Skip to content

Commit

Permalink
fix: properly support skybox in defer
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Nov 5, 2024
1 parent 13f7d45 commit 08a6e2a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/camera/defered.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(:default-initargs
:fakeambient 0f0
:texture-opts
'((0 :element-type :rgba16f); color roughness
'((0 :element-type :rgba32f); color roughness (32 due I am abusing this as a hdr render for skybox)
(1 :element-type :rgba32f); pos ao
(2 :element-type :rgba16f); norm specular
(3 :element-type :rg16f) ; metallic emissive
Expand Down
48 changes: 24 additions & 24 deletions src/postprocess/defer/defer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,31 @@
:fragment (defered-frag :vec2))

(defmethod blit ((scene scene) (postprocess list) (camera defered) time)
"takes defered camera samplers and blits into PREV"
"takes defered camera samplers and blits back into camera (mainly to deal with skybox)"
(declare (ignore postprocess))
(destructuring-bind (s1 s2 s3 s4 _) (sam camera)
(declare (ignore _))
(with-slots (prev bs) *state*
(with-fbo-bound ((fbo prev))
(clear-fbo (fbo prev));; needed for scenes with no envmap
(with-blending (blend camera)
(alexandria:when-let
((actor (find-if #'cube-p (actors scene))))
(paint scene camera actor time))
(map-g #'defer-pipe bs
:fakeambient (fakeambient camera)
:cam-pos (pos camera)
:scene (ubo scene)
;; Samples
:sample1 s1
:sample2 s2
:sample3 s3
:sample4 s4
;; Lights
:dirlights (dir-ubo *state*)
:spotlights (spot-ubo *state*)
:pointlights (point-ubo *state*)
;; Shadows
:dirshadows (dir-sam *state*)
:spotshadows (spot-sam *state*)
:pointshadows (point-sam *state*)))))))
(map-g-into (fbo prev) #'defer-pipe bs
:fakeambient (fakeambient camera)
:cam-pos (pos camera)
:scene (ubo scene)
;; Samples
:sample1 s1
:sample2 s2
:sample3 s3
:sample4 s4
;; Lights
:dirlights (dir-ubo *state*)
:spotlights (spot-ubo *state*)
:pointlights (point-ubo *state*)
;; Shadows
:dirshadows (dir-sam *state*)
:spotshadows (spot-sam *state*)
:pointshadows (point-sam *state*))
(with-fbo-bound ((fbo camera))
(map-g #'pass-pipe bs :sam (first (sam prev)))
(with-setf* ((depth-test-function) #'<=)
(alexandria:when-let ((actor (find-if #'cube-p (actors scene))))
(paint scene camera actor time))))
(map-g-into (fbo prev) #'pass-pipe bs :sam (first (sam camera))))))
61 changes: 30 additions & 31 deletions src/postprocess/defer/ibl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
metallic
color
ao)))
(incf final-color (* emissive color))
(dotimes (i (scene-data-ndir scene))
(with-slots (colors positions lightspace fudge)
dirlights
Expand Down Expand Up @@ -98,41 +99,39 @@
(* (aref lightspace i) (v! frag-pos 1))
(aref fudge i)
i)))))
(v! (+ ambient
final-color)
;; TODO: this alpha is to blend the possible cubemap
(- 1 (step (y color) 0f0)))))
(v! (+ ambient final-color) 1)))

(defpipeline-g defer-ibl-pipe (:points)
:fragment (defered-ibl-frag :vec2))

(defmethod blit ((scene scene-ibl) (postprocess list) (camera defered) time)
(destructuring-bind (s1 s2 s3 s4 _) (sam camera)
(declare (ignore _))
(with-blending (blend camera)
(with-slots (prev bs) *state*
(with-fbo-bound ((fbo prev))
(clear-fbo (fbo prev)) ;; needed for scenes with no envmap
(alexandria:when-let
((actor (find-if #'cube-p (actors scene))))
(paint scene camera actor time))
(map-g #'defer-ibl-pipe bs
:sample1 s1
:sample2 s2
:sample3 s3
:sample4 s4
:cam-pos (pos (current-camera))
:scene (ubo scene)
:time time
;; IBL
:brdf (brdf-sam *state*)
:prefilter (first (sam (prefilter scene)))
:irradiance (first (sam (irradiance scene)))
;; Shadows
:dirshadows (dir-sam *state*)
:spotshadows (spot-sam *state*)
:pointshadows (point-sam *state*)
;; Lights
:dirlights (dir-ubo *state*)
:spotlights (spot-ubo *state*)
:pointlights (point-ubo *state*)))))))
(with-slots (prev bs) *state*
(map-g-into (fbo prev) #'defer-ibl-pipe bs
:sample1 s1
:sample2 s2
:sample3 s3
:sample4 s4
:cam-pos (pos (current-camera))
:scene (ubo scene)
:time time
;; IBL
:brdf (brdf-sam *state*)
:prefilter (first (sam (prefilter scene)))
:irradiance (first (sam (irradiance scene)))
;; Shadows
:dirshadows (dir-sam *state*)
:spotshadows (spot-sam *state*)
:pointshadows (point-sam *state*)
;; Lights
:dirlights (dir-ubo *state*)
:spotlights (spot-ubo *state*)
:pointlights (point-ubo *state*))
(with-fbo-bound ((fbo camera))
(with-blending (blend camera)
(map-g #'pass-pipe bs :sam (first (sam prev)))
(with-setf* ((depth-test-function) #'<=)
(alexandria:when-let ((actor (find-if #'cube-p (actors scene))))
(paint scene camera actor time)))))
(map-g-into (fbo prev) #'pass-pipe bs :sam (first (sam camera))))))
8 changes: 3 additions & 5 deletions src/postprocess/postprocess.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@
(defpipeline-g pass-pipe (:points)
:fragment (pass-frag :vec2))

(defmethod blit
:around (scene (postprocess list) camera time)
(defmethod blit :AROUND (scene (postprocess list) camera time)
(with-setf* ((depth-test-function) NIL
(depth-mask) NIL
(cull-face) NIL)
(call-next-method)))

(defmethod blit (scene (postprocess list) (camera renderable) time)
"main blit, puts forward CAMERA into PREV" ; WHY!? due shared logic with defer?
"puts forward CAMERA into PREV" ; WHY!? due shared logic with defer?
(declare (ignore scene postprocess time))
(with-slots (prev bs) *state*
(map-g-into (fbo prev) #'pass-pipe bs :sam (first (sam camera)))))

(defmethod blit
:after (scene (postprocess list) camera time)
(defmethod blit :AFTER (scene (postprocess list) camera time)
;; 1. ping-pong prev/next
(dolist (post (butlast postprocess))
(with-fbo-bound ((fbo (next *state*)))
Expand Down

0 comments on commit 08a6e2a

Please sign in to comment.