this repo has no description
1const std = @import("std");
2
3const a = @import("a");
4const spall = @import("spall");
5const zm = @import("zmath");
6
7const rayray = @import("rayray");
8const Hittable = rayray.hittable.Hittable;
9const HittableList = rayray.hittable.HittableList;
10const Material = rayray.material.Material;
11const Sphere = rayray.hittable.Sphere;
12
13pub const std_options = .{
14 .log_level = .debug,
15 .logFn = a.log.logFn,
16};
17
18pub fn main() !void {
19 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
20 defer arena.deinit();
21 const allocator = arena.allocator();
22
23 try spall.init("./out/trace.spall");
24 defer spall.deinit();
25
26 spall.init_thread();
27 defer spall.deinit_thread();
28
29 // Setting up the world
30 var material_ground = Material.lambertian(zm.f32x4(0.8, 0.8, 0.0, 1.0));
31 var material_center = Material.lambertian(zm.f32x4(0.7, 0.3, 0.3, 1.0));
32 var material_left = Material.metal(zm.f32x4(0.8, 0.8, 0.8, 1.0), 0.3);
33 var material_right = Material.metal(zm.f32x4(0.8, 0.6, 0.2, 1.0), 1.0);
34
35 var world = HittableList.init(allocator);
36 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(0, -100.5, -1, 0), .radius = 100, .mat = &material_ground }));
37 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(0, 0, -1, 0), .radius = 0.5, .mat = &material_center }));
38 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(-1, 0, -1, 0), .radius = 0.5, .mat = &material_left }));
39 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(1, 0, -1, 0), .radius = 0.5, .mat = &material_right }));
40
41 const s = spall.trace(@src(), "Raytracer", .{});
42
43 // Raytracing part
44 var raytracer = try rayray.Raytracer.init(allocator, world, .{
45 .aspect_ratio = 16.0 / 9.0,
46 .image_width = 400,
47 .samples_per_pixel = 100,
48 .max_depth = 50,
49 });
50 defer raytracer.deinit();
51
52 var timer = try std.time.Timer.start();
53
54 const img = try raytracer.render();
55
56 const rendering_time = timer.lap();
57
58 std.log.info("Image rendered ({}s)", .{rendering_time / std.time.ns_per_s});
59
60 s.end();
61
62 // Saving to file
63 const s_saving = spall.trace(@src(), "Write Image", .{});
64 defer s_saving.end();
65
66 try img.writeToFilePath("./out/out.png", .{ .png = .{} });
67 std.log.info("Image saved to: ./out/out.ong", .{});
68}