diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-12-09 00:02:09 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2022-12-09 00:02:09 +0900 |
| commit | d1a300610db20107af89d57824d5596531037435 (patch) | |
| tree | bcd9595f609171150ad8b208e502209d71cbd4b5 /src/main.zig | |
| parent | 86914985b77ddf5d6d3a3dd6c13deed9d906a471 (diff) | |
| download | RayTracingInOneWeekend.zig-d1a300610db20107af89d57824d5596531037435.tar.gz RayTracingInOneWeekend.zig-d1a300610db20107af89d57824d5596531037435.tar.zst RayTracingInOneWeekend.zig-d1a300610db20107af89d57824d5596531037435.zip | |
5.1
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index e0e5702..e2553b5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -162,6 +162,22 @@ fn generateTwoSpheres(rng: Random, allocator: anytype) !Hittable { return .{ .list = .{ .objects = hittable_objects } }; } +fn generateTwoPerlinSpheres(rng: Random, allocator: anytype) !Hittable { + var hittable_objects = ArrayList(Hittable).init(allocator); + + const perlin = Texture.makeNoise(rng); + var mat1 = try allocator.create(Material); + var mat2 = try allocator.create(Material); + + mat1.* = .{ .diffuse = .{ .albedo = perlin } }; + mat2.* = .{ .diffuse = .{ .albedo = perlin } }; + + try hittable_objects.append(makeSphere(.{ .x = 0, .y = -1000, .z = 0 }, 1000, mat1)); + try hittable_objects.append(makeSphere(.{ .x = 0, .y = 2, .z = 0 }, 2, mat2)); + + return .{ .list = .{ .objects = hittable_objects } }; +} + fn generateRandomScene(rng: Random, allocator: anytype) !Hittable { var hittable_objects = ArrayList(Hittable).init(allocator); @@ -243,7 +259,7 @@ pub fn main() !void { const samples_per_pixel = 50; const max_depth = 50; - const scene = 2; + const scene = 3; // World var world: Hittable = undefined; @@ -263,6 +279,11 @@ pub fn main() !void { lookFrom = .{ .x = 13, .y = 2, .z = 3 }; lookAt = .{ .x = 0, .y = 0, .z = 0 }; vFov = 20.0; + } else if (scene == 3) { + world = try generateTwoPerlinSpheres(rng, allocator); + lookFrom = .{ .x = 13, .y = 2, .z = 3 }; + lookAt = .{ .x = 0, .y = 0, .z = 0 }; + vFov = 20.0; } defer world.deinit(allocator); |
