  by Nikodemus Siivola <  > , 2009 .
;;;;
;;;; Permission is hereby granted, free of charge, to any person
;;;; obtaining a copy of this software and associated documentation files
  ( the " Software " ) , to deal in the Software without restriction ,
;;;; including without limitation the rights to use, copy, modify, merge,
  publish , distribute , sublicense , and/or sell copies of the Software ,
  and to permit persons to whom the Software is furnished to do so ,
;;;; subject to the following conditions:
;;;;
  THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND ,
;;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT .
;;;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT ,
;;;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
;;;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(in-package :raylisp)

(defclass bump-normal (normal)
  ())

(defmethod compute-perturbation-function ((normal bump-normal) transform)
  (let ((inverse (inverse-matrix transform))
        (height (normal-height normal)))
    (declare (single-float height))
    (perturbation-lambda bump-normal (result normal point)
      (declare (optimize speed))
      ;; FIXME: since noise is pretty uniform, full transform seems pointless:
      ;; just extract the scale, maybe?
      (let ((p2 (transform-point point inverse))
            (noise (alloc-vec)))
        (declare (dynamic-extent p2 noise))
        (%noise-vec noise p2)
        (%vec* noise noise height)
        (%vec+ result normal noise)
        (%normalize result result)
        result))))

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation files
 including without limitation the rights to use, copy, modify, merge,
 subject to the following conditions:

 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 FIXME: since noise is pretty uniform, full transform seems pointless:
 just extract the scale, maybe?
  by Nikodemus Siivola <  > , 2009 .
  ( the " Software " ) , to deal in the Software without restriction ,
  publish , distribute , sublicense , and/or sell copies of the Software ,
  and to permit persons to whom the Software is furnished to do so ,
  THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND ,
  MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT .
  CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT ,

(in-package :raylisp)

(defclass bump-normal (normal)
  ())

(defmethod compute-perturbation-function ((normal bump-normal) transform)
  (let ((inverse (inverse-matrix transform))
        (height (normal-height normal)))
    (declare (single-float height))
    (perturbation-lambda bump-normal (result normal point)
      (declare (optimize speed))
      (let ((p2 (transform-point point inverse))
            (noise (alloc-vec)))
        (declare (dynamic-extent p2 noise))
        (%noise-vec noise p2)
        (%vec* noise noise height)
        (%vec+ result normal noise)
        (%normalize result result)
        result))))