diff options
Diffstat (limited to 'src/rtw/texture.zig')
| -rw-r--r-- | src/rtw/texture.zig | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/rtw/texture.zig b/src/rtw/texture.zig index 537ce47..ebbf4cb 100644 --- a/src/rtw/texture.zig +++ b/src/rtw/texture.zig @@ -29,8 +29,8 @@ pub const Texture = union(TextureTag) { ) }; } - pub fn makeNoise(scale: f64, rng: Random) Texture { - return .{ .noise = .{ .perlin = Perlin.init(rng), .scale = scale } }; + pub fn makeNoise(allocator: std.mem.Allocator, scale: f64, rng: Random) !Texture { + return .{ .noise = try NoiseTexture.init(allocator, rng, scale) }; } pub fn value(tx: Texture, u: f64, v: f64, p: Vec3) Color { @@ -85,6 +85,17 @@ pub const NoiseTexture = struct { perlin: Perlin, scale: f64, + fn init(allocator: std.mem.Allocator, rng: Random, scale: f64) !NoiseTexture { + return .{ + .perlin = try Perlin.init(allocator, rng), + .scale = scale, + }; + } + + fn deinit(tx: NoiseTexture) void { + tx.perlin.deinit(); + } + fn value(tx: NoiseTexture, u: f64, v: f64, p: Vec3) Color { _ = u; _ = v; |
