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.checker(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, scence.camera);
32 defer raytracer.deinit();
33
34 var timer = try std.time.Timer.start();
35
36 const img = try raytracer.render();
37
38 printRenderTime(timer.lap());
39
40 try img.writeToFilePath("./out/out.png", .{ .png = .{} });
41 std.log.info("Image saved to: ./out/out.png", .{});
42}
43
44fn printRenderTime(t: u64) void {
45 var rt = t;
46
47 const days = rt / std.time.ns_per_day;
48 rt = rt - (days * std.time.ns_per_day);
49
50 const hours = rt / std.time.ns_per_hour;
51 rt = rt - (hours * std.time.ns_per_hour);
52
53 const minutes = rt / std.time.ns_per_min;
54 rt = rt - (minutes * std.time.ns_per_min);
55
56 const seconds = rt / std.time.ns_per_s;
57 rt = rt - (seconds * std.time.ns_per_s);
58
59 const ms = rt / std.time.ns_per_ms;
60 rt = rt - (ms * std.time.ns_per_ms);
61
62 // std.log.info("Image rendered ({}s)", .{rendering_time / std.time.ns_per_s});
63 if (days == 0) {
64 std.log.info("Image rendered in: {}h {}m {}s {}ms", .{ hours, minutes, seconds, ms });
65 } else {
66 std.log.info("Image rendered in: {}d {}h {}m {}s {}ms", .{ days, hours, minutes, seconds, ms });
67 }
68}