Skip to content

Commit

Permalink
move fog to defer
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Nov 2, 2024
1 parent 2fc7932 commit c7dfc46
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
6 changes: 3 additions & 3 deletions scenic.asd
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
(:file "postprocess/defer/defer")
(:file "postprocess/defer/ibl")
(:file "postprocess/defer/ssao")
(:file "postprocess/dof")
(:file "postprocess/ssr")
(:file "postprocess/fog/iqfog")
(:file "postprocess/defer/ssr")
(:file "postprocess/defer/fog/iqfog")
(:file "postprocess/defer/fog/unrealfog")
(:file "postprocess/bloom/render")
(:file "postprocess/bloom/bloom")
(:file "postprocess/bloom/blit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
(defpipeline-g iqfog-pipe (:points)
:fragment (iqfog-frag :vec2))

;; FIXME: assumes that 1st light is the sun
(defmethod blit (scene (postprocess iqfog) (camera defered) time)
(with-slots (bs density color1 color2) postprocess
(map-g #'iqfog-pipe bs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
(check-type height single-float)
(check-type terminator-angle single-float))

(defmethod print-object ((obj unrealfog) stream)
(print-unreadable-object (obj stream :type T :identity T)
(with-slots (density falloff height terminator-angle) obj
(format stream "DFHA: ~a ~a ~a ~a"
density falloff height terminator-angle))))

(defun-g unrealfog-frag ((uv :vec2)
&uniform
(world-clip :mat4)
Expand Down Expand Up @@ -80,16 +86,18 @@
(defpipeline-g unrealfog-pipe (:points)
:fragment (unrealfog-frag :vec2))

;; FIXME: assumes the first light is the sun
(defmethod blit (scene (postprocess unrealfog) (camera defered) time)
(with-slots (bs falloff terminator-angle density height) postprocess
(map-g #'unrealfog-pipe bs
:sam-pos (second (sam camera))
:sam (first (sam (prev *state*)))
:light-pos (pos (first (lights scene)))
:sam-pos (second (sam camera))
:cam-pos (pos camera)
:sam (first (sam (prev *state*)))
:world-clip (world->clip camera)
:fog-params
(v! (* density (expt 2 (* (- falloff)
(- (z (pos camera)) height))))
(v! (* density
(expt 2 (* (- falloff)
(- (z (pos camera)) height))))
falloff
terminator-angle)
:light-pos (pos (first (lights scene)))
:cam-pos (pos camera))))
terminator-angle))))
File renamed without changes.
46 changes: 28 additions & 18 deletions src/postprocess/dither.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

(defclass dither (postprocess)
((dithers :documentation "list of samplers of dither patterns")
(precision :initarg :precision
:accessor dither-precision
(precision :initarg :precision
:accessor dither-precision
:documentation "color depth"))
(:default-initargs
:precision 32f0)
Expand All @@ -12,8 +12,7 @@
(defun make-dither (&rest args)
(apply #'make-instance 'dither args))

(defmethod (setf dither-precision)
:before (new-value (obj dither))
(defmethod (setf dither-precision) :before (new-value (obj dither))
(check-type new-value single-float))

(defmethod initialize-instance :before ((obj dither) &key precision)
Expand All @@ -34,19 +33,23 @@
(with-slots (dithers) obj
(setf dithers (alexandria:rotate dithers))))

#+nil
(defmethod free ((obj dither))
(free (slot-value obj 'dithers)))
(defmethod dither-prev ((obj dither))
(with-slots (dithers) obj
(setf dithers (alexandria:rotate dithers -1))))

(defun-g channel-error ((col :float) (col-min :float) (col-max :float))
(defun-g channel-error
((col :float)
(col-min :float)
(col-max :float))
(let ((range (abs (- col-min col-max)))
(arange (abs (- col col-min))))
(/ arange range)))

(defun-g dithered-channel ((err :float)
(dither-block-uv :vec2)
(dither-steps :float)
(dither-pattern :sampler-2d))
(defun-g dithered-channel
((err :float)
(dither-block-uv :vec2)
(dither-steps :float)
(dither-pattern :sampler-2d))
(let* ((err (/ (floor (* err dither-steps))
dither-steps))
(dither-uv (v! err 0))
Expand Down Expand Up @@ -79,10 +82,11 @@
(+ (x yuva) (* (y yuva) 1.8556))
(w yuva))))

(defun-g psx-dither ((sam :sampler-2d)
(uv :vec2)
(precision :float)
(dither-texture :sampler-2d))
(defun-g psx-dither
((sam :sampler-2d)
(uv :vec2)
(precision :float)
(dither-texture :sampler-2d))
(let* ((yuv (rgb->yuv (texture sam uv)))
;; Clamp the YUV color to specified color depth (default: 32, 5 bits per channel, as per playstation hardware)
(col1 (/ (floor (* yuv precision)) precision))
Expand Down Expand Up @@ -123,13 +127,19 @@
(w yuv))))
(yuv->rgb yuv)))

(defun-g dither-frag ((uv :vec2) &uniform (precision :float) (sam :sampler-2d) (dither-sam :sampler-2d))
(defun-g dither-frag
((uv :vec2)
&uniform
(precision :float)
(sam :sampler-2d)
(dither-sam :sampler-2d))
(psx-dither sam uv precision dither-sam))

(defpipeline-g dither-pipe (:points)
:fragment (dither-frag :vec2))

(defmethod blit (scene (postprocess dither) (camera renderable) time)
(defmethod blit (scene (postprocess dither) camera time)
(declare (ignore scene camera time))
(with-slots (bs dithers precision) postprocess
(map-g #'dither-pipe bs
:precision precision
Expand Down

0 comments on commit c7dfc46

Please sign in to comment.