(in-package :fraggle)

;;------------------------------------------------------------
;; GPU Funcs
;;
  If these end up being used a lot then move them to Nineveh
;;
  ( decided to make ' remap ' in  )

(defun-g 11to01 ((x :float))
  (+ 0.5 (* 0.5 x)))

(defun-g 11to01 ((x :vec2))
  (+ (v2! 0.5) (* 0.5 x)))

(defun-g 11to01 ((x :vec3))
  (+ (v3! 0.5) (* 0.5 x)))

(defun-g 11to01 ((x :vec4))
  (+ (v4! 0.5) (* 0.5 x)))

(defun-g 01to11 ((x :float))
  (- (* 2 x) 1))

(defun-g 01to11 ((x :vec2))
  (- (* 2 x) (v2! 1)))

(defun-g 01to11 ((x :vec3))
  (- (* 2 x) (v3! 1)))

(defun-g 01to11 ((x :vec4))
  (- (* 2 x) (v4! 1)))

;; blend-color

(defun-g blend ((src :float) (dst :float))
  (+ src (* dst (- 1f0 src))))

(defun-g blend ((src :vec2) (dst :vec2))
  (+ src (* dst (- (v2! 1f0) src))))

(defun-g blend ((src :vec3) (dst :vec3))
  (+ src (* dst (- (v3! 1f0) src))))

(defun-g blend ((src :vec4) (dst :vec4))
  (let ((src-rgb (s~ src :xyz))
        (dst-rgb (s~ dst :xyz))
        (src-alpha (w src))
        (dst-alpha (w dst)))
    (v! (+ src-rgb (* dst-rgb (- (v3! 1) src-rgb)))
        (+ src-alpha (* dst-alpha (- 1f0 src-alpha))))))

------------------------------------------------------------
 GPU Funcs


 blend-color
(in-package :fraggle)

  If these end up being used a lot then move them to Nineveh
  ( decided to make ' remap ' in  )

(defun-g 11to01 ((x :float))
  (+ 0.5 (* 0.5 x)))

(defun-g 11to01 ((x :vec2))
  (+ (v2! 0.5) (* 0.5 x)))

(defun-g 11to01 ((x :vec3))
  (+ (v3! 0.5) (* 0.5 x)))

(defun-g 11to01 ((x :vec4))
  (+ (v4! 0.5) (* 0.5 x)))

(defun-g 01to11 ((x :float))
  (- (* 2 x) 1))

(defun-g 01to11 ((x :vec2))
  (- (* 2 x) (v2! 1)))

(defun-g 01to11 ((x :vec3))
  (- (* 2 x) (v3! 1)))

(defun-g 01to11 ((x :vec4))
  (- (* 2 x) (v4! 1)))


(defun-g blend ((src :float) (dst :float))
  (+ src (* dst (- 1f0 src))))

(defun-g blend ((src :vec2) (dst :vec2))
  (+ src (* dst (- (v2! 1f0) src))))

(defun-g blend ((src :vec3) (dst :vec3))
  (+ src (* dst (- (v3! 1f0) src))))

(defun-g blend ((src :vec4) (dst :vec4))
  (let ((src-rgb (s~ src :xyz))
        (dst-rgb (s~ dst :xyz))
        (src-alpha (w src))
        (dst-alpha (w dst)))
    (v! (+ src-rgb (* dst-rgb (- (v3! 1) src-rgb)))
        (+ src-alpha (* dst-alpha (- 1f0 src-alpha))))))
