Skip to content

Commit

Permalink
fxaa3: init wrapper over nineveh
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Nov 2, 2024
1 parent c7dfc46 commit c12a1d6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions scenic.asd
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
(:file "postprocess/hdr")
(:file "postprocess/hdr-acesfilm")
(:file "postprocess/dither")
(:file "postprocess/fxaa3")
(:file "postprocess/defer/defer")
(:file "postprocess/defer/ibl")
(:file "postprocess/defer/ssao")
Expand Down
66 changes: 66 additions & 0 deletions src/postprocess/fxaa3.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
(in-package #:scenic)

(defclass fxaa3 (postprocess)
((aliasing-removal
:accessor fxaa3-aliasing-removal
:initarg :aliasing-removal
:documentation "Amount of sub pixel aliasing removal. Choose the amount of sub-pixel aliasing removal. This can effect sharpness.")
(min-contrast
:accessor fxaa3-min-contrast
:initarg :min-contrast
:documentation "Minimum local contrast required to apply. The minimum amount of local contrast required to apply algorithm.")
(min-threshold
:accessor fxaa3-min-threshold
:initarg :min-threshold
:documentation "Edge threshold min. Trims the algorithm from processing darks.")
(settings
:reader fxaa3-settings
:documentation "vec3 sent as an uniform"))
(:default-initargs
:aliasing-removal 0.75
:min-contrast 0.166
:min-threshold 0.0833))

(defmethod initialize-instance :before ((obj fxaa3) &key aliasing-removal min-contrast min-threshold)
(check-type aliasing-removal (float 0 1)) ; off - default - softer
(check-type min-contrast (float 0.063 0.333)) ; slower - default - faster
(check-type min-threshold (float 0.0312 0.0833))); slower - faster (default)

(defmethod (setf fxaa3-aliasing-removal) :before (new-value (obj fxaa3))
(check-type new-value (float 0 1)))
(defmethod (setf fxaa3-min-contrast) :before (new-value (obj fxaa3))
(check-type new-value (float 0.063 0.333)))
(defmethod (setf fxaa3-min-threshold) :before (new-value (obj fxaa3))
(check-type new-value (float 0.0312 0.0833)))

(defmethod (setf fxaa3-aliasing-removal) :after (new-value (obj fxaa3))
(setf (x (slot-value obj 'settings)) new-value))
(defmethod (setf fxaa3-min-contrast) :after (new-value (obj fxaa3))
(setf (y (slot-value obj 'settings)) new-value))
(defmethod (setf fxaa3-min-threshold) :after (new-value (obj fxaa3))
(setf (z (slot-value obj 'settings)) new-value))

(defmethod initialize-instance :after ((obj fxaa3) &key aliasing-removal min-contrast min-threshold)
(setf (slot-value obj 'settings)
(v! aliasing-removal min-contrast min-threshold)))

(defun-g fxaa3-frag
((uv :vec2)
&uniform
(sam :sampler-2d)
(one-over-res :vec2)
(settings :vec3))
(nineveh.anti-aliasing:fxaa3
uv sam one-over-res (x settings) (y settings) (z settings)))

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

(defmethod blit (scene (postprocess fxaa3) camera time)
(let ((sam (first (sam (prev *state*)))))
(destructuring-bind (width height)
(texture-base-dimensions (sampler-texture sam))
(map-g #'fxaa3-pipe (bs postprocess)
:settings (fxaa3-settings postprocess)
:sam (first (sam (prev *state*)))
:one-over-res (v! (/ 1 width) (/ 1 height))))))

0 comments on commit c12a1d6

Please sign in to comment.