Skip to content

Commit

Permalink
bloom: use sampling on merge pass, refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Nov 1, 2024
1 parent f8d0934 commit a551927
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
23 changes: 11 additions & 12 deletions src/postprocess/bloom/blit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
;; Extract Brightest Parts
;;
(with-fbo-bound ((aref fbos 0))
(clear-fbo (aref fbos 0))
(map-g #'bloom-threshold-pipe (bs postprocess)
:intensity (intensity-gamma postprocess)
:threshold (threshold postprocess)
Expand All @@ -21,15 +22,11 @@
;;
;; Downsample ⬇️
;;
(with-fbo-bound ((aref fbos 1))
(map-g #'bloom-blur-pipe (bs postprocess)
:delta 1f0
:sam (aref samplers 0)
:x (aref widths 0)
:y (aref heights 0)))
(loop :for src :from 1 :to 3 :do
(loop :for src :from 0 :to 3 :do
(with-fbo-bound ((aref fbos (1+ src)))
(clear-fbo (aref fbos (1+ src)))
(map-g #'bloom-blur-pipe (bs postprocess)
:delta 1f0
:sam (aref samplers src)
:x (aref widths src)
:y (aref heights src))))
Expand All @@ -44,13 +41,15 @@
:sam (aref samplers (+ 1 dst))
:x (aref widths (+ 1 dst))
:y (aref heights (+ 1 dst))
:delta 0.5f0))))
:delta 0.5))))
;;
;; Render (fbo captured in :AFTER)
;; Render (captured fbo in :AFTER)
;;
(map-g #'add-textures-pipe (bs postprocess)
:sam1 (aref samplers 0)
:sam2 (first (sam (prev *state*))))))
#+nil
(draw-tex-br
:sam2 (first (sam (prev *state*)))
:x (aref widths 0)
:y (aref heights 0))))
;;#+nil
(draw-tex-tr
(aref (bloom-fbo-samplers (fbos postprocess)) 0)))
2 changes: 1 addition & 1 deletion src/postprocess/bloom/bloom.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(:default-initargs
:intensity 1f0 ;; 1.0 - 10.0
:threshold 1f0
:threshold-soft 0.5
:threshold-soft 0.5 ;; > wider bloom
:blending (make-blending-params :source-rgb :one :destination-rgb :one)))

;; https://github.com/DukeChiang/DCET/blob/52cde71d239e6023daf42a0d84f04041c235e413/Server/Packages/UnityEngine/Unity/Mathf.cs#L681
Expand Down
17 changes: 9 additions & 8 deletions src/postprocess/bloom/render.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@
(sam :sampler-2d)
(x :float)
(y :float))
(let* ((texture-size (texture-size sam 0))
(o (* (v! x y x y)
(let* ((o (* (v! x y x y)
(v! (- delta) (- delta) delta delta)))
(s (+ (texture sam (+ uv (s~ o :xy)))
(texture sam (+ uv (s~ o :zy)))
(texture sam (+ uv (s~ o :xw)))
(texture sam (+ uv (s~ o :zw))))))
(* s .25)))
(s (+ (s~ (texture sam (+ uv (s~ o :xy))) :xyz)
(s~ (texture sam (+ uv (s~ o :zy))) :xyz)
(s~ (texture sam (+ uv (s~ o :xw))) :xyz)
(s~ (texture sam (+ uv (s~ o :zw))) :xyz))))
(v! (* s 0.25) 1)))

(defun-g bloom-blur-frag
((uv :vec2)
Expand Down Expand Up @@ -90,10 +89,12 @@
(defun-g add-textures-frag
((uv :vec2)
&uniform
(x :float)
(y :float)
(sam1 :sampler-2d)
(sam2 :sampler-2d))
(+ (texture sam1 uv)
(texture sam2 uv)))
(sample-box uv 0.5 sam2 x y)))

(defpipeline-g add-textures-pipe (:points)
:fragment (add-textures-frag :vec2))

0 comments on commit a551927

Please sign in to comment.