Skip to content

Commit fd2ae89

Browse files
committed
Volume samplers
1 parent b02a74e commit fd2ae89

12 files changed

+49
-5
lines changed

sources/noise/noise.swift

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extension Noise
1919
{
2020
for j in 0 ..< width
2121
{
22-
let x:Double = Double(i) + 0.5,
23-
y:Double = Double(j) + 0.5
22+
let x:Double = Double(j) + 0.5,
23+
y:Double = Double(i) + 0.5
2424
samples.append((x, y, self.evaluate(x, y)))
2525
}
2626
}
@@ -32,11 +32,55 @@ extension Noise
3232
{
3333
var samples:[UInt8] = []
3434
samples.reserveCapacity(width * height)
35-
for y in 0 ..< height
35+
for i in 0 ..< height
36+
{
37+
for j in 0 ..< width
38+
{
39+
let x:Double = Double(j) + 0.5,
40+
y:Double = Double(i) + 0.5
41+
samples.append(UInt8(max(0, min(255, self.evaluate(x, y) + offset))))
42+
}
43+
}
44+
return samples
45+
}
46+
47+
public
48+
func sample_volume(width:Int, height:Int, depth:Int) -> [(Double, Double, Double, Double)]
49+
{
50+
var samples:[(Double, Double, Double, Double)] = []
51+
samples.reserveCapacity(width * height * depth)
52+
for i in 0 ..< depth
53+
{
54+
for j in 0 ..< height
55+
{
56+
for k in 0 ..< width
57+
{
58+
let x:Double = Double(k) + 0.5,
59+
y:Double = Double(j) + 0.5,
60+
z:Double = Double(i) + 0.5
61+
samples.append((x, y, z, self.evaluate(x, y, z)))
62+
}
63+
}
64+
}
65+
return samples
66+
}
67+
68+
public
69+
func sample_volume_saturated_to_u8(width:Int, height:Int, depth:Int, offset:Double = 0.5) -> [UInt8]
70+
{
71+
var samples:[UInt8] = []
72+
samples.reserveCapacity(width * height * depth)
73+
for i in 0 ..< depth
3674
{
37-
for x in 0 ..< width
75+
for j in 0 ..< height
3876
{
39-
samples.append(UInt8(max(0, min(255, self.evaluate(Double(x), Double(y)) + offset))))
77+
for k in 0 ..< width
78+
{
79+
let x:Double = Double(k) + 0.5,
80+
y:Double = Double(j) + 0.5,
81+
z:Double = Double(i) + 0.5
82+
samples.append(UInt8(max(0, min(255, self.evaluate(x, y, z) + offset))))
83+
}
4084
}
4185
}
4286
return samples

tests/banner_FBM.png

275 Bytes
Loading

tests/banner_cell2d.png

637 Bytes
Loading

tests/banner_cell3d.png

-197 Bytes
Loading

tests/banner_simplex2d.png

-447 Bytes
Loading

tests/banner_supersimplex2d.png

35 Bytes
Loading

tests/banner_supersimplex3d.png

46 Bytes
Loading

tests/cell2d.png

219 Bytes
Loading

tests/cell3d.png

65 Bytes
Loading

tests/simplex2d.png

337 Bytes
Loading

tests/super_simplex2d.png

653 Bytes
Loading

tests/super_simplex3d.png

8 KB
Loading

0 commit comments

Comments
 (0)