this repo has no description
1const std = @import("std");
2
3const aa = @import("a");
4
5const rayray = @import("rayray");
6const Hittable = rayray.hittable.Hittable;
7const HittableList = rayray.hittable.HittableList;
8const Material = rayray.material.Material;
9const Sphere = rayray.hittable.Sphere;
10const zm = rayray.zmath;
11
12const scences = @import("scences.zig");
13
14pub const std_options = .{
15 .log_level = .debug,
16 .logFn = aa.log.logFn,
17};
18
19pub fn main() !void {
20 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
21 defer arena.deinit();
22 const allocator = arena.allocator();
23
24 // Setting up the world
25 var scence = try scences.inOneWeekend(allocator);
26 defer scence.deinit();
27
28 std.log.info("World created", .{});
29
30 // Raytracing part
31 var raytracer = try rayray.Raytracer.init(allocator, scence.world, .{
32 .aspect_ratio = 16.0 / 9.0,
33 .image_width = 400,
34 .samples_per_pixel = 50,
35 .max_depth = 50,
36
37 .vfov = 20,
38 .look_from = zm.f32x4(20, 6, 6, 0),
39 .look_at = zm.f32x4(0, 0, 0, 0),
40
41 .defocus_angle = 0.6,
42 .focus_dist = 18,
43 });
44 defer raytracer.deinit();
45
46 var timer = try std.time.Timer.start();
47
48 const img = try raytracer.render();
49
50 const rendering_time = timer.lap();
51 var rt = rendering_time;
52
53 const days = rt / std.time.ns_per_day;
54 rt = rt - (days * std.time.ns_per_day);
55
56 const hours = rt / std.time.ns_per_hour;
57 rt = rt - (hours * std.time.ns_per_hour);
58
59 const minutes = rt / std.time.ns_per_min;
60 rt = rt - (minutes * std.time.ns_per_min);
61
62 const seconds = rt / std.time.ns_per_s;
63 rt = rt - (seconds * std.time.ns_per_s);
64
65 const ms = rt / std.time.ns_per_ms;
66 rt = rt - (ms * std.time.ns_per_ms);
67
68 // std.log.info("Image rendered ({}s)", .{rendering_time / std.time.ns_per_s});
69 if (days == 0) {
70 std.log.info("Image rendered in: {}h {}m {}s {}ms", .{ hours, minutes, seconds, ms });
71 } else {
72 std.log.info("Image rendered in: {}d {}h {}m {}s {}ms", .{ days, hours, minutes, seconds, ms });
73 }
74
75 try img.writeToFilePath("./out/out.png", .{ .png = .{} });
76 std.log.info("Image saved to: ./out/out.png", .{});
77}