aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-07-15 13:38:20 +0900
committernsfisis <nsfisis@gmail.com>2023-07-15 13:38:20 +0900
commitfe58fdc2e53a01be94b4dbc845dcdbbdae0a7889 (patch)
treeaf5b7055f6f3b63effc0909f13a690b8a409c8d9
parentdbf75192fa25e4df1f4a0e69eeb41198e6fe064c (diff)
downloadRayTracingInOneWeekend.zig-fe58fdc2e53a01be94b4dbc845dcdbbdae0a7889.tar.gz
RayTracingInOneWeekend.zig-fe58fdc2e53a01be94b4dbc845dcdbbdae0a7889.tar.zst
RayTracingInOneWeekend.zig-fe58fdc2e53a01be94b4dbc845dcdbbdae0a7889.zip
7.4
-rw-r--r--src/main.zig34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/main.zig b/src/main.zig
index 70da3fc..f0da441 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -258,6 +258,29 @@ fn generateEarthScene(allocator: anytype) !Hittable {
return .{ .list = .{ .objects = hittable_objects } };
}
+fn generateSimpleLightScene(rng: Random, allocator: anytype) !Hittable {
+ var hittable_objects = ArrayList(Hittable).init(allocator);
+
+ const perlin = try Texture.makeNoise(allocator, 4.0, 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));
+
+ const light = Texture.makeSolid(rgb(4, 4, 4));
+ var mat3 = try allocator.create(Material);
+
+ mat3.* = .{ .diffuse_light = .{ .emit = light } };
+
+ try hittable_objects.append(.{ .xyRect = .{ .x0 = 3.0, .x1 = 5.0, .y0 = 1.0, .y1 = 3.0, .k = -2.0, .material = mat3 } });
+
+ return .{ .list = .{ .objects = hittable_objects } };
+}
+
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
@@ -270,10 +293,10 @@ pub fn main() !void {
const aspect_ratio = 3.0 / 2.0;
const image_width = 600;
const image_height = @floatToInt(comptime_int, @divTrunc(image_width, aspect_ratio));
- const samples_per_pixel = 50;
const max_depth = 50;
+ var samples_per_pixel: u32 = 50;
- const scene = 4;
+ const scene = 5;
// World
var world: Hittable = undefined;
@@ -308,6 +331,13 @@ pub fn main() !void {
lookFrom = .{ .x = 13, .y = 2, .z = 3 };
lookAt = .{ .x = 0, .y = 0, .z = 0 };
vFov = 20.0;
+ } else if (scene == 5) {
+ world = try generateSimpleLightScene(rng, allocator);
+ background = rgb(0, 0, 0);
+ lookFrom = .{ .x = 26, .y = 3, .z = 6 };
+ lookAt = .{ .x = 0, .y = 2, .z = 0 };
+ vFov = 20.0;
+ samples_per_pixel = 400;
}
defer world.deinit(allocator);