A define's body is walked and parenthesised now (sex#55). The four written as divisions fold to exactly the doubles they replace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
462 lines
24 KiB
Scheme
462 lines
24 KiB
Scheme
;;; Simplex noise as vsapi has it: SimplexNoiseOctave, the OpenSimplex
|
|
;;; variant with precomputed contribution lists, and
|
|
;;; NormalizedSimplexNoise, octaves of it squashed by tanh into 0..1.
|
|
;;; Every map layer and the terrain itself sample these, so this is
|
|
;;; ported operation for operation, in doubles where C# has doubles.
|
|
|
|
(pub include stdint.h)
|
|
(include stdlib.h math.h)
|
|
|
|
;;; As the C# writes them. Its divisions are folded at compile time,
|
|
;;; and C's are too, to the same doubles.
|
|
(define STRETCH-2D -0.211324865405187)
|
|
(define SQUISH-2D 0.366025403784439)
|
|
(define STRETCH-3D (/ -1.0 6.0))
|
|
(define SQUISH-3D (/ 1.0 3.0))
|
|
(define NORM-2D (/ 1.0 47.0))
|
|
(define NORM-3D (/ 1.0 103.0))
|
|
(define NORM-2D-WARP 0.020435461373899677)
|
|
(pub define MAX-VALUE-3D 0.9871465422297019)
|
|
(define VALUE-MULTIPLIER 1.2)
|
|
(pub define MAX-OCTAVES 16)
|
|
|
|
(var gradients-2d [double 16] #(5 2 2 5 -5 2 -2 5 5 -2 2 -5 -5 -2 -2 -5))
|
|
|
|
(var gradients-3d [double 72]
|
|
#(-11 4 4 -4 11 4 -4 4 11
|
|
11 4 4 4 11 4 4 4 11
|
|
-11 -4 4 -4 -11 4 -4 -4 11
|
|
11 -4 4 4 -11 4 4 -4 11
|
|
-11 4 -4 -4 11 -4 -4 4 -11
|
|
11 4 -4 4 11 -4 4 4 -11
|
|
-11 -4 -4 -4 -11 -4 -4 -4 -11
|
|
11 -4 -4 4 -11 -4 4 -4 -11))
|
|
|
|
;;; Generated from vsapi SimplexOctave.cs by a script; do not edit.
|
|
(var base2d-0 [int 9]
|
|
#(1 1 0 1 0 1 0 0 0))
|
|
(var base2d-1 [int 9]
|
|
#(1 1 0 1 0 1 2 1 1))
|
|
(var base3d-0 [int 16]
|
|
#(0 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1))
|
|
(var base3d-1 [int 16]
|
|
#(2 1 1 0 2 1 0 1 2 0 1 1 3 1 1 1))
|
|
(var base3d-2 [int 24]
|
|
#(1 1 0 0 1 0 1 0 1 0 0 1 2 1 1 0 2 1 0 1 2 0 1 1))
|
|
(var p2d [int 24]
|
|
#(0 0 1 -1 0 0 -1 1 0 2 1 1 1 2 2 0 1 2 0 2 1 0 0 0))
|
|
(var lookup-pairs-2d [int 24]
|
|
#(0 1 1 0 4 1 17 0 20 2 21 2 22 5 23 5 26 4 39 3 42 4 43 3))
|
|
(var p3d [int 216]
|
|
#(0 0 1 -1 0 0 1 0 -1 0 0 -1 1 0 0 0 1 -1 0 0 -1 0 1 0 0 -1 1
|
|
0 2 1 1 0 1 1 1 -1 0 2 1 0 1 1 1 -1 1 0 2 0 1 1 1 -1 1 1
|
|
1 3 2 1 0 3 1 2 0 1 3 2 0 1 3 1 0 2 1 3 0 2 1 3 0 1 2
|
|
1 1 1 0 0 2 2 0 0 1 1 0 1 0 2 0 2 0 1 1 0 0 1 2 0 0 2
|
|
2 0 0 0 0 1 1 -1 1 2 0 0 0 0 1 -1 1 1 2 0 0 0 0 1 1 1 -1
|
|
2 3 1 1 1 2 0 0 2 2 3 1 1 1 2 2 0 0 2 3 1 1 1 2 0 2 0
|
|
2 1 1 -1 1 2 0 0 2 2 1 1 -1 1 2 2 0 0 2 1 -1 1 1 2 0 0 2
|
|
2 1 -1 1 1 2 0 2 0 2 1 1 1 -1 2 2 0 0 2 1 1 1 -1 2 0 2 0))
|
|
(var lookup-pairs-3d [int 144]
|
|
#(0 2 1 1 2 2 5 1 6 0 7 0 32 2 34 2 129 1 133 1 160 5 161 5
|
|
518 0 519 0 546 4 550 4 645 3 647 3 672 5 673 5 674 4 677 3 678 4 679 3
|
|
680 13 681 13 682 12 685 14 686 12 687 14 712 20 714 18 809 21 813 23 840 20 841 21
|
|
1198 19 1199 22 1226 18 1230 19 1325 23 1327 22 1352 15 1353 17 1354 15 1357 17 1358 16 1359 16
|
|
1360 11 1361 10 1362 11 1365 10 1366 9 1367 9 1392 11 1394 11 1489 10 1493 10 1520 8 1521 8
|
|
1878 9 1879 9 1906 7 1910 7 2005 6 2007 6 2032 8 2033 8 2034 7 2037 6 2038 7 2039 6))
|
|
|
|
;;; One vertex a lattice cell contributes. The C# builds linked lists
|
|
;;; of these once, statically; here they are a pool and `next' is an
|
|
;;; index into it, -1 at a list's end.
|
|
(record contribution ((dx double) (dy double) (dz double)
|
|
(xsb int) (ysb int) (zsb int) (next int)))
|
|
|
|
(var pool [contribution 256])
|
|
(var pool-used int 0)
|
|
(var lookup-2d [int 64])
|
|
(var lookup-3d [int 2048])
|
|
(var tables-ready bool false)
|
|
|
|
(fn contribution-2d ((multiplier double) (xsb int) (ysb int)) int
|
|
(var c (* contribution) (& [pool pool-used]))
|
|
(= (. c dx) (- (- xsb) (* multiplier SQUISH-2D)))
|
|
(= (. c dy) (- (- ysb) (* multiplier SQUISH-2D)))
|
|
(= (. c dz) 0)
|
|
(= (. c xsb) xsb)
|
|
(= (. c ysb) ysb)
|
|
(= (. c zsb) 0)
|
|
(= (. c next) -1)
|
|
(++ pool-used)
|
|
(return (- pool-used 1)))
|
|
|
|
(fn contribution-3d ((multiplier double) (xsb int) (ysb int) (zsb int)) int
|
|
(var c (* contribution) (& [pool pool-used]))
|
|
(= (. c dx) (- (- xsb) (* multiplier SQUISH-3D)))
|
|
(= (. c dy) (- (- ysb) (* multiplier SQUISH-3D)))
|
|
(= (. c dz) (- (- zsb) (* multiplier SQUISH-3D)))
|
|
(= (. c xsb) xsb)
|
|
(= (. c ysb) ysb)
|
|
(= (. c zsb) zsb)
|
|
(= (. c next) -1)
|
|
(++ pool-used)
|
|
(return (- pool-used 1)))
|
|
|
|
;;; The static constructor of SimplexNoiseOctave, 2D and 3D parts.
|
|
(fn build-tables () void
|
|
(var heads-2d [int 6])
|
|
(for (var i int 0) (< i 24) (+= i 4)
|
|
(var base (* int) (if (== [p2d i] 0) base2d-0 base2d-1))
|
|
(var previous int -1)
|
|
(for (var k int 0) (< k 9) (+= k 3)
|
|
(var current int (contribution-2d [base k] [base (+ k 1)] [base (+ k 2)]))
|
|
(if (< previous 0)
|
|
(= [heads-2d (/ i 4)] current)
|
|
(= (. [pool previous] next) current))
|
|
(= previous current))
|
|
(= (. [pool previous] next)
|
|
(contribution-2d [p2d (+ i 1)] [p2d (+ i 2)] [p2d (+ i 3)])))
|
|
(for (var i int 0) (< i 64) (++ i)
|
|
(= [lookup-2d i] -1))
|
|
(for (var i int 0) (< i 24) (+= i 2)
|
|
(= [lookup-2d [lookup-pairs-2d i]] [heads-2d [lookup-pairs-2d (+ i 1)]]))
|
|
|
|
(var heads-3d [int 24])
|
|
(for (var i int 0) (< i 216) (+= i 9)
|
|
(var base (* int) base3d-0)
|
|
(var base-len int 16)
|
|
(if (== [p3d i] 1) (= base base3d-1)
|
|
(== [p3d i] 2) (do (= base base3d-2) (= base-len 24)))
|
|
(var previous int -1)
|
|
(for (var k int 0) (< k base-len) (+= k 4)
|
|
(var current int (contribution-3d [base k] [base (+ k 1)] [base (+ k 2)] [base (+ k 3)]))
|
|
(if (< previous 0)
|
|
(= [heads-3d (/ i 9)] current)
|
|
(= (. [pool previous] next) current))
|
|
(= previous current))
|
|
(var a int (contribution-3d [p3d (+ i 1)] [p3d (+ i 2)] [p3d (+ i 3)] [p3d (+ i 4)]))
|
|
(= (. [pool previous] next) a)
|
|
(= (. [pool a] next)
|
|
(contribution-3d [p3d (+ i 5)] [p3d (+ i 6)] [p3d (+ i 7)] [p3d (+ i 8)])))
|
|
(for (var i int 0) (< i 2048) (++ i)
|
|
(= [lookup-3d i] -1))
|
|
(for (var i int 0) (< i 144) (+= i 2)
|
|
(= [lookup-3d [lookup-pairs-3d i]] [heads-3d [lookup-pairs-3d (+ i 1)]]))
|
|
(= tables-ready true))
|
|
|
|
;;; Builds the shared lookup tables. Call once before any threads
|
|
;;; sample noise; constructors call it too.
|
|
(pub fn noise-init () void
|
|
(if (! tables-ready)
|
|
(build-tables)))
|
|
|
|
(pub record simplex-octave ((perm [u8 256]) (perm-2d [u8 256]) (perm-3d [u8 256])))
|
|
|
|
(ops simplex-octave
|
|
(pub fn make ((seed i64)) simplex-octave
|
|
(noise-init)
|
|
(var o simplex-octave)
|
|
(var source [u8 256])
|
|
(for (var i int 0) (< i 256) (++ i)
|
|
(= [source i] (cast i u8)))
|
|
(var s u64 (cast seed u64))
|
|
(for (var k int 0) (< k 3) (++ k)
|
|
(= s (+ (* s 6364136223846793005) 1442695040888963407)))
|
|
(for (var i int 255) (>= i 0) (-- i)
|
|
(= s (+ (* s 6364136223846793005) 1442695040888963407))
|
|
(var r int (cast (% (+ (cast s i64) 31) (+ i 1)) int))
|
|
(if (< r 0)
|
|
(+= r (+ i 1)))
|
|
(= [(. o perm) i] [source r])
|
|
(= [(. o perm-2d) i] (cast (& [(. o perm) i] 14) u8))
|
|
(= [(. o perm-3d) i] (cast (* (% [(. o perm) i] 24) 3) u8))
|
|
(= [source r] [source i]))
|
|
(return o))
|
|
|
|
(pub fn eval-2d ((self (* const simplex-octave)) (x double) (y double)) double
|
|
(var stretch double (* (+ x y) STRETCH-2D))
|
|
(var xs double (+ x stretch))
|
|
(var ys double (+ y stretch))
|
|
(var xsb int (cast (floor xs) int))
|
|
(var ysb int (cast (floor ys) int))
|
|
(var squish double (* (+ xsb ysb) SQUISH-2D))
|
|
(var dx0 double (- x (+ xsb squish)))
|
|
(var dy0 double (- y (+ ysb squish)))
|
|
(var xins double (- xs xsb))
|
|
(var yins double (- ys ysb))
|
|
(var in-sum double (+ xins yins))
|
|
(var hash u32 (c-bit-or (cast (+ (- xins yins) 1) u32)
|
|
(<< (cast in-sum u32) 1)
|
|
(<< (cast (+ in-sum yins) u32) 2)
|
|
(<< (cast (+ in-sum xins) u32) 4)))
|
|
(var value double 0.0)
|
|
(for (var c int [lookup-2d hash]) (>= c 0) (= c (. [pool c] next))
|
|
(var dx double (+ dx0 (. [pool c] dx)))
|
|
(var dy double (+ dy0 (. [pool c] dy)))
|
|
(var attn double (- 2.0 (* dx dx) (* dy dy)))
|
|
(if (> attn 0.0)
|
|
(do
|
|
(var px int (+ xsb (. [pool c] xsb)))
|
|
(var py int (+ ysb (. [pool c] ysb)))
|
|
(var i int [(. self perm-2d) (& (+ [(. self perm) (& px 255)] py) 255)])
|
|
(var part double (+ (* [gradients-2d i] dx) (* [gradients-2d (+ i 1)] dy)))
|
|
(*= attn attn)
|
|
(+= value (* attn attn part)))))
|
|
(return (* value NORM-2D)))
|
|
|
|
(pub fn eval-3d ((self (* const simplex-octave)) (x double) (y double) (z double)) double
|
|
(var stretch double (* (+ x y z) STRETCH-3D))
|
|
(var xs double (+ x stretch))
|
|
(var ys double (+ y stretch))
|
|
(var zs double (+ z stretch))
|
|
(var xsb int (cast (floor xs) int))
|
|
(var ysb int (cast (floor ys) int))
|
|
(var zsb int (cast (floor zs) int))
|
|
(var squish double (* (+ xsb ysb zsb) SQUISH-3D))
|
|
(var dx0 double (- x (+ xsb squish)))
|
|
(var dy0 double (- y (+ ysb squish)))
|
|
(var dz0 double (- z (+ zsb squish)))
|
|
(var xins double (- xs xsb))
|
|
(var yins double (- ys ysb))
|
|
(var zins double (- zs zsb))
|
|
(var in-sum double (+ xins yins zins))
|
|
(var hash int (c-bit-or (cast (+ (- yins zins) 1) int)
|
|
(<< (cast (+ (- xins yins) 1) int) 1)
|
|
(<< (cast (+ (- xins zins) 1) int) 2)
|
|
(<< (cast in-sum int) 3)
|
|
(<< (cast (+ in-sum zins) int) 5)
|
|
(<< (cast (+ in-sum yins) int) 7)
|
|
(<< (cast (+ in-sum xins) int) 9)))
|
|
(if (< hash 0) (= hash 0))
|
|
(if (> hash 2047) (= hash 2047))
|
|
(var value double 0.0)
|
|
(for (var c int [lookup-3d hash]) (>= c 0) (= c (. [pool c] next))
|
|
(var dx double (+ dx0 (. [pool c] dx)))
|
|
(var dy double (+ dy0 (. [pool c] dy)))
|
|
(var dz double (+ dz0 (. [pool c] dz)))
|
|
(var attn double (- 2.0 (* dx dx) (* dy dy) (* dz dz)))
|
|
(if (> attn 0.0)
|
|
(do
|
|
(var px int (+ xsb (. [pool c] xsb)))
|
|
(var py int (+ ysb (. [pool c] ysb)))
|
|
(var pz int (+ zsb (. [pool c] zsb)))
|
|
(var i int [(. self perm-3d)
|
|
(& (+ [(. self perm) (& (+ [(. self perm) (& px 255)] py) 255)] pz) 255)])
|
|
(var part double (+ (* [gradients-3d i] dx) (* [gradients-3d (+ i 1)] dy)
|
|
(* [gradients-3d (+ i 2)] dz)))
|
|
(*= attn attn)
|
|
(+= value (* attn attn part)))))
|
|
(return (* value NORM-3D))))
|
|
|
|
;;; NormalizedSimplexNoise. Octave i samples at frequencies[i] and is
|
|
;;; weighted so the sum stays in a known range before tanh.
|
|
(pub record simplex-noise
|
|
((count int) (frequencies [double MAX-OCTAVES]) (amplitudes [double MAX-OCTAVES])
|
|
(scaled-2d [double MAX-OCTAVES]) (scaled-3d [double MAX-OCTAVES])
|
|
(octaves [simplex-octave MAX-OCTAVES])))
|
|
|
|
(ops simplex-noise
|
|
(pub fn make ((amplitudes (* const double)) (frequencies (* const double)) (count int)
|
|
(seed i64)) (* simplex-noise)
|
|
(var n (* simplex-noise) (calloc 1 (sizeof simplex-noise)))
|
|
(= (. n count) count)
|
|
(var norm-3d double 0)
|
|
(var norm-2d double 0)
|
|
(for (var i int 0) (< i count) (++ i)
|
|
(= [(. n frequencies) i] [frequencies i])
|
|
(= [(. n amplitudes) i] [amplitudes i])
|
|
(= [(. n octaves) i]
|
|
(simplex-octave/make (cast (+ (* (cast seed u64) 65599) (cast i u64)) i64)))
|
|
(+= norm-3d (* [amplitudes i] (pow (- 0.74 0.1) (+ i 1))))
|
|
(+= norm-2d (* [amplitudes i] (pow (- 0.83 0.1) (+ i 1)))))
|
|
(for (var i int 0) (< i count) (++ i)
|
|
(= [(. n scaled-2d) i] (/ [amplitudes i] norm-2d))
|
|
(= [(. n scaled-3d) i] (/ [amplitudes i] norm-3d)))
|
|
(return n))
|
|
|
|
;; FromDefaultOctaves: octave i at 2^i * BASE-FREQUENCY, weighted
|
|
;; PERSISTENCE^i.
|
|
(pub fn octaves ((count int) (base-frequency double) (persistence double) (seed i64))
|
|
(* simplex-noise)
|
|
(var frequencies [double MAX-OCTAVES])
|
|
(var amplitudes [double MAX-OCTAVES])
|
|
(for (var i int 0) (< i count) (++ i)
|
|
(= [frequencies i] (* (pow 2 i) base-frequency))
|
|
(= [amplitudes i] (pow persistence i)))
|
|
(return (simplex-noise/make amplitudes frequencies count seed)))
|
|
|
|
(pub fn noise-2d ((self (* const simplex-noise)) (x double) (y double)) double
|
|
(var value double 0)
|
|
(for (var i int 0) (< i (. self count)) (++ i)
|
|
(var f double [(. self frequencies) i])
|
|
(+= value (* VALUE-MULTIPLIER (.eval-2d (& [(. self octaves) i]) (* x f) (* y f))
|
|
[(. self scaled-2d) i])))
|
|
(return (+ (* (tanh value) 0.5) 0.5)))
|
|
|
|
(pub fn noise-3d ((self (* const simplex-noise)) (x double) (y double) (z double)) double
|
|
(var value double 0)
|
|
(for (var i int 0) (< i (. self count)) (++ i)
|
|
(var f double [(. self frequencies) i])
|
|
(+= value (* VALUE-MULTIPLIER (.eval-3d (& [(. self octaves) i]) (* x f) (* y f) (* z f))
|
|
[(. self scaled-3d) i])))
|
|
(return (+ (* (tanh value) 0.5) 0.5))))
|
|
|
|
;;; SimplexNoise: plain octave sums, no normalising and no tanh. The
|
|
;;; rock strata thickness maps and the strata distortion use it.
|
|
(pub record simplex-sum
|
|
((count int) (frequencies [double MAX-OCTAVES]) (amplitudes [double MAX-OCTAVES])
|
|
(octaves [simplex-octave MAX-OCTAVES])))
|
|
|
|
(ops simplex-sum
|
|
(pub fn make ((amplitudes (* const double)) (frequencies (* const double)) (count int)
|
|
(seed i64)) (* simplex-sum)
|
|
(var n (* simplex-sum) (calloc 1 (sizeof simplex-sum)))
|
|
(= (. n count) count)
|
|
(for (var i int 0) (< i count) (++ i)
|
|
(= [(. n frequencies) i] [frequencies i])
|
|
(= [(. n amplitudes) i] [amplitudes i])
|
|
(= [(. n octaves) i]
|
|
(simplex-octave/make (cast (+ (* (cast seed u64) 65599) (cast i u64)) i64))))
|
|
(return n))
|
|
|
|
(pub fn noise-2d ((self (* const simplex-sum)) (x double) (y double)) double
|
|
(var value double 0)
|
|
(for (var i int 0) (< i (. self count)) (++ i)
|
|
(var f double [(. self frequencies) i])
|
|
(+= value (* (.eval-2d (& [(. self octaves) i]) (* x f) (* y f)) [(. self amplitudes) i])))
|
|
(return value))
|
|
|
|
;; Each octave's value pulled toward 0 by its threshold, so only
|
|
;; peaks above it count.
|
|
(pub fn noise-2d-thresholded ((self (* const simplex-sum)) (x double) (y double)
|
|
(thresholds (* const double))) double
|
|
(var value double 0)
|
|
(for (var i int 0) (< i (. self count)) (++ i)
|
|
(var f double [(. self frequencies) i])
|
|
(var v double (* (.eval-2d (& [(. self octaves) i]) (* x f) (* y f)) [(. self amplitudes) i]))
|
|
(+= value (if (> v 0.0) (fmax 0.0 (- v [thresholds i])) (fmin 0.0 (+ v [thresholds i])))))
|
|
(return value)))
|
|
|
|
;;; Generated from vsapi SimplexOctave.cs warpUpgradeVectors2D; do not edit.
|
|
(var warp-vectors [double 384]
|
|
#(0.9238795325112866 0.3826834323650898 4.97524354451166 2.060813352245919 -4.975243544511659 -2.060813352245919
|
|
0.7071067811865476 0.7071067811865476 3.807886552931954 3.807886552931954 3.8078865529319543 -3.8078865529319543
|
|
1.0 0.0 4.975243544511659 2.0608133522459187 4.975243544511659 -2.0608133522459187
|
|
0.3826834323650897 0.9238795325112867 0.0 5.385164807134505 5.385164807134505 0.0
|
|
1.0 0.0 4.975243544511659 2.0608133522459187 -4.975243544511659 2.0608133522459187
|
|
0.9238795325112867 -0.3826834323650897 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
0.9238795325112866 0.3826834323650898 4.975243544511659 2.060813352245919 4.97524354451166 2.060813352245919
|
|
0.7071067811865476 0.7071067811865476 3.8078865529319543 -3.8078865529319543 3.807886552931954 3.807886552931954
|
|
0.7071067811865476 0.7071067811865476 3.807886552931954 3.807886552931954 -3.8078865529319543 3.8078865529319543
|
|
0.3826834323650898 0.9238795325112866 2.060813352245919 4.97524354451166 2.060813352245919 4.975243544511659
|
|
-0.3826834323650897 0.9238795325112867 -5.385164807134505 0.0 0.0 5.385164807134505
|
|
0.0 1.0 -2.0608133522459187 4.975243544511659 2.0608133522459187 4.975243544511659
|
|
0.9238795325112867 0.3826834323650897 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
0.0 1 2.0608133522459187 -4.975243544511659 2.0608133522459187 4.975243544511659
|
|
0.7071067811865476 0.7071067811865476 -3.8078865529319543 3.8078865529319543 3.807886552931954 3.807886552931954
|
|
0.3826834323650898 0.9238795325112866 -2.060813352245919 -4.975243544511659 2.060813352245919 4.97524354451166
|
|
-1.0 0.0 4.975243544511659 -2.0608133522459187 4.975243544511659 2.0608133522459187
|
|
-0.3826834323650897 0.9238795325112867 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
-0.9238795325112866 0.3826834323650898 4.975243544511659 -2.060813352245919 -4.97524354451166 2.060813352245919
|
|
-0.7071067811865476 0.7071067811865476 3.8078865529319543 3.8078865529319543 -3.807886552931954 3.807886552931954
|
|
-0.9238795325112866 0.3826834323650898 4.97524354451166 -2.060813352245919 4.975243544511659 -2.060813352245919
|
|
-0.7071067811865476 0.7071067811865476 3.807886552931954 -3.807886552931954 -3.8078865529319543 -3.8078865529319543
|
|
-1.0 0.0 4.975243544511659 -2.0608133522459187 -4.975243544511659 -2.0608133522459187
|
|
-0.9238795325112867 -0.3826834323650897 5.385164807134505 0.0 0.0 -5.385164807134505
|
|
0.3826834323650897 0.9238795325112867 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
0.0 1.0 2.0608133522459187 4.975243544511659 -2.0608133522459187 4.975243544511659
|
|
-0.7071067811865476 0.7071067811865476 -3.8078865529319543 -3.8078865529319543 -3.807886552931954 3.807886552931954
|
|
-0.3826834323650898 0.9238795325112866 -2.060813352245919 4.975243544511659 -2.060813352245919 4.97524354451166
|
|
-0.7071067811865476 0.7071067811865476 3.807886552931954 -3.807886552931954 3.8078865529319543 3.8078865529319543
|
|
-0.3826834323650898 0.9238795325112866 2.060813352245919 -4.97524354451166 -2.060813352245919 4.975243544511659
|
|
-0.9238795325112867 0.3826834323650897 0.0 -5.385164807134505 -5.385164807134505 0.0
|
|
0.0 1.0 -2.0608133522459187 -4.975243544511659 -2.0608133522459187 4.975243544511659
|
|
1.0 0.0 4.975243544511659 -2.0608133522459187 -4.975243544511659 -2.0608133522459187
|
|
0.9238795325112867 0.3826834323650897 5.385164807134505 0.0 0.0 -5.385164807134505
|
|
0.9238795325112866 -0.3826834323650898 4.97524354451166 -2.060813352245919 4.975243544511659 -2.060813352245919
|
|
0.7071067811865476 -0.7071067811865476 3.807886552931954 -3.807886552931954 -3.8078865529319543 -3.8078865529319543
|
|
0.9238795325112866 -0.3826834323650898 4.975243544511659 -2.060813352245919 -4.97524354451166 2.060813352245919
|
|
0.7071067811865476 -0.7071067811865476 3.8078865529319543 3.8078865529319543 -3.807886552931954 3.807886552931954
|
|
1.0 0.0 4.975243544511659 -2.0608133522459187 4.975243544511659 2.0608133522459187
|
|
0.3826834323650897 -0.9238795325112867 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
0.9238795325112867 -0.3826834323650897 0.0 -5.385164807134505 -5.385164807134505 0.0
|
|
0.0 -1.0 -2.0608133522459187 -4.975243544511659 -2.0608133522459187 4.975243544511659
|
|
0.7071067811865476 -0.7071067811865476 3.807886552931954 -3.807886552931954 3.8078865529319543 3.8078865529319543
|
|
0.3826834323650898 -0.9238795325112866 2.060813352245919 -4.97524354451166 -2.060813352245919 4.975243544511659
|
|
0.7071067811865476 -0.7071067811865476 -3.8078865529319543 -3.8078865529319543 -3.807886552931954 3.807886552931954
|
|
0.3826834323650898 -0.9238795325112866 -2.060813352245919 4.975243544511659 -2.060813352245919 4.97524354451166
|
|
-0.3826834323650897 -0.9238795325112867 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
0.0 -1.0 2.0608133522459187 4.975243544511659 -2.0608133522459187 4.975243544511659
|
|
-0.9238795325112866 -0.3826834323650898 4.975243544511659 2.060813352245919 4.97524354451166 2.060813352245919
|
|
-0.7071067811865476 -0.7071067811865476 3.8078865529319543 -3.8078865529319543 3.807886552931954 3.807886552931954
|
|
-1.0 0.0 4.975243544511659 2.0608133522459187 -4.975243544511659 2.0608133522459187
|
|
-0.9238795325112867 0.3826834323650897 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
-1.0 0.0 4.975243544511659 2.0608133522459187 4.975243544511659 -2.0608133522459187
|
|
-0.3826834323650897 -0.9238795325112867 0.0 5.385164807134505 5.385164807134505 0.0
|
|
-0.9238795325112866 -0.3826834323650898 4.97524354451166 2.060813352245919 -4.975243544511659 -2.060813352245919
|
|
-0.7071067811865476 -0.7071067811865476 3.807886552931954 3.807886552931954 3.8078865529319543 -3.8078865529319543
|
|
-0.7071067811865476 -0.7071067811865476 -3.8078865529319543 3.8078865529319543 3.807886552931954 3.807886552931954
|
|
-0.3826834323650898 -0.9238795325112866 -2.060813352245919 -4.975243544511659 2.060813352245919 4.97524354451166
|
|
-0.9238795325112867 -0.3826834323650897 3.807886552931954 3.807886552931954 -3.807886552931954 3.807886552931954
|
|
0.0 -1.0 2.0608133522459187 -4.975243544511659 2.0608133522459187 4.975243544511659
|
|
0.3826834323650897 -0.9238795325112867 -5.385164807134505 0.0 0.0 5.385164807134505
|
|
0.0 -1.0 -2.0608133522459187 4.975243544511659 2.0608133522459187 4.975243544511659
|
|
-0.7071067811865476 -0.7071067811865476 3.807886552931954 3.807886552931954 -3.8078865529319543 3.8078865529319543
|
|
-0.3826834323650898 -0.9238795325112866 2.060813352245919 4.97524354451166 2.060813352245919 4.975243544511659))
|
|
|
|
;;; SimplexNoiseOctave.EvaluateFairWarpVector: a 2D warp from a pair of
|
|
;;; octaves, rotated so its directions are fairer than two independent
|
|
;;; noises'.
|
|
(fn fair-warp-octave ((ox (* const simplex-octave)) (oz (* const simplex-octave))
|
|
(x double) (y double) (out-x (* double)) (out-y (* double))) void
|
|
(var stretch double (* (+ x y) STRETCH-2D))
|
|
(var xs double (+ x stretch))
|
|
(var ys double (+ y stretch))
|
|
(var xsb int (cast (floor xs) int))
|
|
(var ysb int (cast (floor ys) int))
|
|
(-= xs xsb)
|
|
(-= ys ysb)
|
|
(var squish double (* (+ xsb ysb) SQUISH-2D))
|
|
(var dx0 double (- x (+ xsb squish)))
|
|
(var dy0 double (- y (+ ysb squish)))
|
|
(var in-sum double (+ xs ys))
|
|
(var hash u32 (c-bit-or (cast (+ (- xs ys) 1) u32)
|
|
(<< (cast in-sum u32) 1)
|
|
(<< (cast (+ in-sum ys) u32) 2)
|
|
(<< (cast (+ in-sum xs) u32) 4)))
|
|
(var dist-x double 0)
|
|
(var dist-y double 0)
|
|
(for (var c int [lookup-2d hash]) (>= c 0) (= c (. [pool c] next))
|
|
(var dx double (+ dx0 (. [pool c] dx)))
|
|
(var dy double (+ dy0 (. [pool c] dy)))
|
|
(var attn double (- 2.0 (* dx dx) (* dy dy)))
|
|
(if (> attn 0.0)
|
|
(do
|
|
(var px int (+ xsb (. [pool c] xsb)))
|
|
(var py int (+ ysb (. [pool c] ysb)))
|
|
(var i int [(. ox perm-2d) (& (+ [(. ox perm) (& px 255)] py) 255)])
|
|
(var j int [(. oz perm-2d) (& (+ [(. oz perm) (& px 255)] py) 255)])
|
|
(var k int (* (+ (* i 8) j) 3))
|
|
(var rx double [warp-vectors k])
|
|
(var ry double [warp-vectors (+ k 1)])
|
|
(var a double (+ (* [warp-vectors (+ k 2)] dx) (* [warp-vectors (+ k 3)] dy)))
|
|
(var b double (+ (* [warp-vectors (+ k 4)] dx) (* [warp-vectors (+ k 5)] dy)))
|
|
(*= attn attn)
|
|
(*= attn attn)
|
|
(+= dist-x (* attn (+ (* a rx) (* b ry))))
|
|
(+= dist-y (* attn (- (* a ry) (* b rx)))))))
|
|
(= (* out-x) (* dist-x NORM-2D-WARP))
|
|
(= (* out-y) (* dist-y NORM-2D-WARP)))
|
|
|
|
;;; SimplexNoise.NoiseFairWarpVector over the octaves of two noises
|
|
;;; made alike.
|
|
(pub fn fair-warp ((nx (* const simplex-sum)) (nz (* const simplex-sum)) (x double) (y double)
|
|
(out-x (* double)) (out-y (* double))) void
|
|
(= (* out-x) 0)
|
|
(= (* out-y) 0)
|
|
(for (var i int 0) (< i (. nx count)) (++ i)
|
|
(var f double [(. nx frequencies) i])
|
|
(var hx double)
|
|
(var hy double)
|
|
(fair-warp-octave (& [(. nx octaves) i]) (& [(. nz octaves) i]) (* x f) (* y f) (& hx) (& hy))
|
|
(+= (* out-x) (* hx [(. nx amplitudes) i]))
|
|
(+= (* out-y) (* hy [(. nx amplitudes) i]))))
|