Fix types in the images collection to work with TR's handling of NaN.

This commit is contained in:
Vincent St-Amour 2012-05-25 15:01:33 -04:00
parent 142158c0cb
commit 263016f6f3
2 changed files with 10 additions and 10 deletions

View File

@ -482,23 +482,23 @@
(trace-directional-light alpha-fm rgb-fm z-fm normal-fm x-min x-max y-min y-max)) (trace-directional-light alpha-fm rgb-fm z-fm normal-fm x-min x-max y-min y-max))
;; two Gaussian blurs by half of σ^2 is equivalent to one Gaussian blur by σ^2 ;; two Gaussian blurs by half of σ^2 is equivalent to one Gaussian blur by σ^2
(define σ^2 (sqr (* (min w h) (shadow-blur)))) (define σ^2 (exact->inexact (sqr (* (min w h) (shadow-blur)))))
;; blur the shadow to simulate internal scatter ;; blur the shadow to simulate internal scatter
(define shadow-fm (define shadow-fm
(cond [bg-fm (cond [bg-fm
(let* ([fm (flomap-blur raw-shadow-fm (sqrt (* 1/3 σ^2)))] (let* ([fm (flomap-blur raw-shadow-fm (flsqrt (* 1/3 σ^2)))]
[fm (fm* fm bg-fm)] [fm (fm* fm bg-fm)]
[fm (flomap-blur fm (sqrt (* 1/3 σ^2)))]) [fm (flomap-blur fm (flsqrt (* 1/3 σ^2)))])
fm)] fm)]
[else [else
(flomap-blur raw-shadow-fm (sqrt (* 2/3 σ^2)))])) (flomap-blur raw-shadow-fm (flsqrt (* 2/3 σ^2)))]))
;; pass 2: trace from the viewer ;; pass 2: trace from the viewer
(define-values (reflected-fm raw-transmitted-fm) (define-values (reflected-fm raw-transmitted-fm)
(trace-directional-view alpha-fm rgb-fm z-fm normal-fm shadow-fm x-min x-max y-min y-max)) (trace-directional-view alpha-fm rgb-fm z-fm normal-fm shadow-fm x-min x-max y-min y-max))
;; simulate scatter some more ;; simulate scatter some more
(define transmitted-fm (flomap-blur raw-transmitted-fm (sqrt (* 1/3 σ^2)))) (define transmitted-fm (flomap-blur raw-transmitted-fm (flsqrt (* 1/3 σ^2))))
;; add all the light together, convert to premultiplied-alpha flomap ;; add all the light together, convert to premultiplied-alpha flomap
(let* ([fm (fm+ (fm+ diffracted-fm transmitted-fm) reflected-fm)] (let* ([fm (fm+ (fm+ diffracted-fm transmitted-fm) reflected-fm)]
[fm (flomap-append-components alpha-fm fm)] [fm (flomap-append-components alpha-fm fm)]

View File

@ -160,13 +160,13 @@
;; calculates the standard deviation of downscaling blur, assuming linear interpolation will be ;; calculates the standard deviation of downscaling blur, assuming linear interpolation will be
;; carried out on the blurred image ;; carried out on the blurred image
(: stddev-for-scale (Nonnegative-Flonum -> Nonnegative-Flonum)) (: stddev-for-scale (Flonum -> Flonum))
(define (stddev-for-scale scale) (define (stddev-for-scale scale)
(define var (- (/ box-filter-variance (sqr scale)) (define var (- (/ box-filter-variance (sqr scale))
triangle-filter-variance)) triangle-filter-variance))
(abs (flsqrt (max 0.0 var)))) (abs (flsqrt (max 0.0 var))))
(: flomap-scale*-x (flomap Nonnegative-Flonum Exact-Nonnegative-Integer -> flomap)) (: flomap-scale*-x (flomap Flonum Exact-Nonnegative-Integer -> flomap))
(define (flomap-scale*-x fm scale width) (define (flomap-scale*-x fm scale width)
(cond [(scale . = . 1.0) fm] (cond [(scale . = . 1.0) fm]
[(scale . > . 1.0) (flomap-scale*-x/linear fm scale width)] [(scale . > . 1.0) (flomap-scale*-x/linear fm scale width)]
@ -174,7 +174,7 @@
(flomap-gaussian-blur-x fm (stddev-for-scale scale))) (flomap-gaussian-blur-x fm (stddev-for-scale scale)))
(flomap-scale*-x/linear low-res-fm scale width)])) (flomap-scale*-x/linear low-res-fm scale width)]))
(: flomap-scale*-y (flomap Nonnegative-Flonum Exact-Nonnegative-Integer -> flomap)) (: flomap-scale*-y (flomap Flonum Exact-Nonnegative-Integer -> flomap))
(define (flomap-scale*-y fm scale height) (define (flomap-scale*-y fm scale height)
(cond [(scale . = . 1.0) fm] (cond [(scale . = . 1.0) fm]
[(scale . > . 1.0) (flomap-scale*-y/linear fm scale height)] [(scale . > . 1.0) (flomap-scale*-y/linear fm scale height)]
@ -182,7 +182,7 @@
(flomap-gaussian-blur-y fm (stddev-for-scale scale))) (flomap-gaussian-blur-y fm (stddev-for-scale scale)))
(flomap-scale*-y/linear low-res-fm scale height)])) (flomap-scale*-y/linear low-res-fm scale height)]))
(: flomap-scale*-x/linear (flomap Nonnegative-Flonum Exact-Nonnegative-Integer -> flomap)) (: flomap-scale*-x/linear (flomap Flonum Exact-Nonnegative-Integer -> flomap))
(define (flomap-scale*-x/linear fm s new-w) (define (flomap-scale*-x/linear fm s new-w)
(match-define (flomap vs c w h) fm) (match-define (flomap vs c w h) fm)
(define w-1 (fx- w 1)) (define w-1 (fx- w 1))
@ -200,7 +200,7 @@
[else (flvector-ref vs (unsafe-fx+ i0 c))])) [else (flvector-ref vs (unsafe-fx+ i0 c))]))
(fl-convex-combination v0 v1 (- scaled-x floor-scaled-x))])))) (fl-convex-combination v0 v1 (- scaled-x floor-scaled-x))]))))
(: flomap-scale*-y/linear (flomap Nonnegative-Flonum Exact-Nonnegative-Integer -> flomap)) (: flomap-scale*-y/linear (flomap Flonum Exact-Nonnegative-Integer -> flomap))
(define (flomap-scale*-y/linear fm s new-h) (define (flomap-scale*-y/linear fm s new-h)
(match-define (flomap vs c w h) fm) (match-define (flomap vs c w h) fm)
(define h-1 (fx- h 1)) (define h-1 (fx- h 1))