Skip to content

Commit

Permalink
fmod -> mod (R6RS handles floating point modulo)
Browse files Browse the repository at this point in the history
  • Loading branch information
laqrix committed Jan 3, 2012
1 parent a02ab0e commit 02ac403
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions math.ss
Expand Up @@ -10,11 +10,6 @@

(define (sqr x) (* x x))

(define (fmod n modulus)
(if (negative? n)
(do ([n n (+ n modulus)]) ((positive? n) n))
(do ([n n (- n modulus)]) ((negative? n) (+ n modulus)))))

(define (clamp x xmin xmax)
(max xmin (min x xmax)))

Expand Down Expand Up @@ -171,13 +166,13 @@
(- (step edge0 x) (step edge1 x)))

(define (pulsetrain edge period x)
(pulse edge period (fmod x period)))
(pulse edge period (mod x period)))

(define (smoothpulse e0 e1 e2 e3 x)
(- (smoothstep e0 e1 x) (smoothstep e2 e3 x)))

(define (smoothpulsetrain e0 e1 e2 e3 period x)
(smoothpulse e0 e1 e2 e3 (fmod x period)))
(smoothpulse e0 e1 e2 e3 (mod x period)))

(define (fadeout g g-avg featuresize fwidth)
(mix-num g g-avg (smoothstep .2 .6 (/ fwidth featuresize))))
Expand Down
2 changes: 1 addition & 1 deletion objects.ss
Expand Up @@ -171,7 +171,7 @@
0.5))

(define (plane-point->texture object point)
(make-vec (fmod (vec-i point) 1) (fmod (vec-j point) 1) 0))
(make-vec (mod (vec-i point) 1) (mod (vec-j point) 1) 0))

(define (polyhedron-intersections obj ray)
(let ([origin (<ray> origin ray)]
Expand Down
12 changes: 6 additions & 6 deletions user-shaders.ss
Expand Up @@ -45,7 +45,7 @@
(let ([pnt (point->surface object intersect-point)]
[Nf (faceforward (vec-normalize normal) incoming)])
(let* ([t (vec-j pnt)]
[tmod (fmod (* t frequency) 1)])
[tmod (mod (* t frequency) 1)])
(color-mul Os
(if (< tmod .5)
Cs
Expand All @@ -57,9 +57,9 @@
(define-shader checker ([Kd 1] [Ka .5] [frequency 4] [blackcolor black])
(let ([pnt (point->surface object intersect-point)]
[Nf (faceforward (vec-normalize normal) incoming)])
(let ([xmod (fmod (* (vec-i pnt) frequency) (+ 1 EPSILON))]
[ymod (fmod (* (vec-j pnt) frequency) (+ 1 EPSILON))]
[zmod (fmod (* (vec-k pnt) frequency) (+ 1 EPSILON))])
(let ([xmod (mod (* (vec-i pnt) frequency) (+ 1 EPSILON))]
[ymod (mod (* (vec-j pnt) frequency) (+ 1 EPSILON))]
[zmod (mod (* (vec-k pnt) frequency) (+ 1 EPSILON))])
(color-mul Os
(if (< zmod .5)
(if (< xmod .5)
Expand Down Expand Up @@ -249,8 +249,8 @@
([Ka 1] [Kd .75] [Ks .4] [roughness .1] [specularcolor white]
[density .25] [frequency 20])
(let ([st (point->texture object (point->surface object intersect-point))])
(if (or (< (fmod (* (vec-i st) frequency) 1) density)
(< (fmod (* (vec-j st) frequency) 1) density))
(if (or (< (mod (* (vec-i st) frequency) 1) density)
(< (mod (* (vec-j st) frequency) 1) density))
(let ([Nf (faceforward (vec-normalize normal) incoming)]
[V (vec-normalize (vec-reverse incoming))])
(values
Expand Down

0 comments on commit 02ac403

Please sign in to comment.