diff options
| -rw-r--r-- | src/rtw/perlin.zig | 13 | ||||
| -rw-r--r-- | src/rtw/texture.zig | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/rtw/perlin.zig b/src/rtw/perlin.zig index b00291f..c60bb34 100644 --- a/src/rtw/perlin.zig +++ b/src/rtw/perlin.zig @@ -78,6 +78,19 @@ pub const Perlin = struct { return perlinInterp(c, u_, v_, w_); } + pub fn turb(perlin: Perlin, p: Point3, depth: u8) f64 { + var accum: f64 = 0.0; + var p_ = p; + var weight: f64 = 1.0; + var i: u8 = 0; + while (i < depth) : (i += 1) { + accum += weight * perlin.noise(p_); + weight *= 0.5; + p_ = p_.mul(2.0); + } + return @fabs(accum); + } + fn permute(rng: Random, p: []usize, n: usize) void { var i = n - 1; while (i > 0) : (i -= 1) { diff --git a/src/rtw/texture.zig b/src/rtw/texture.zig index ebbf4cb..6322ac0 100644 --- a/src/rtw/texture.zig +++ b/src/rtw/texture.zig @@ -99,7 +99,6 @@ pub const NoiseTexture = struct { fn value(tx: NoiseTexture, u: f64, v: f64, p: Vec3) Color { _ = u; _ = v; - const t = tx.perlin.noise(p.mul(tx.scale)); - return rgb(1, 1, 1).mul((1.0 + t) / 2.0); + return rgb(1, 1, 1).mul(tx.perlin.turb(p.mul(tx.scale), 7)); } }; |
