From c12a1d6136021d685074ff8143309503bbd68164 Mon Sep 17 00:00:00 2001 From: azimut Date: Sat, 2 Nov 2024 01:28:22 -0300 Subject: [PATCH] fxaa3: init wrapper over nineveh --- scenic.asd | 1 + src/postprocess/fxaa3.lisp | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/postprocess/fxaa3.lisp diff --git a/scenic.asd b/scenic.asd index 748cf49..cf1f7ae 100644 --- a/scenic.asd +++ b/scenic.asd @@ -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") diff --git a/src/postprocess/fxaa3.lisp b/src/postprocess/fxaa3.lisp new file mode 100644 index 0000000..a23c327 --- /dev/null +++ b/src/postprocess/fxaa3.lisp @@ -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))))))