aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-01-28 22:16:25 +0900
committernsfisis <nsfisis@gmail.com>2023-01-28 22:16:25 +0900
commitd3e46dfda0a4d376c4648ecad5012e2302ddcea6 (patch)
tree1a8f37aedd52da13ac2267139fce0be38a334069
parent84b019965f63d02f0d8f6e3a108f7d29ffa23076 (diff)
downloadRayTracingInOneWeekend.zig-d3e46dfda0a4d376c4648ecad5012e2302ddcea6.tar.gz
RayTracingInOneWeekend.zig-d3e46dfda0a4d376c4648ecad5012e2302ddcea6.tar.zst
RayTracingInOneWeekend.zig-d3e46dfda0a4d376c4648ecad5012e2302ddcea6.zip
5.6
-rw-r--r--src/rtw/perlin.zig13
-rw-r--r--src/rtw/texture.zig3
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));
}
};