this repo has no description
at main 2.3 kB view raw
1const std = @import("std"); 2const Options = std.Options; 3 4const aa = @import("a"); 5 6const rayray = @import("rayray"); 7const Hittable = rayray.hittable.Hittable; 8const HittableList = rayray.hittable.HittableList; 9const Material = rayray.material.Material; 10const Sphere = rayray.hittable.Sphere; 11const zm = rayray.zmath; 12 13const build_options = rayray.build_options; 14 15const scenes = @import("scenes.zig"); 16 17pub const std_options = Options{ 18 .log_level = .debug, 19 .logFn = aa.log.logFn, 20}; 21 22pub fn main() !void { 23 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); 24 defer arena.deinit(); 25 const allocator = arena.allocator(); 26 27 // var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 28 // const allocator = gpa.allocator(); 29 // defer { 30 // const deinit_status = gpa.deinit(); 31 // //fail test; can't try in defer as defer is executed after we return 32 // if (deinit_status == .leak) @panic("LEAK"); 33 // } 34 35 // Setting up the world 36 var scene = rayray.Scene.init(allocator); 37 defer scene.deinit(); 38 39 try scenes.checker(&scene); 40 41 std.log.info("World created", .{}); 42 43 // Raytracing part 44 var raytracer = try rayray.Raytracer.init(allocator, scene); 45 defer raytracer.deinit(); 46 47 var timer = try std.time.Timer.start(); 48 49 const img = try raytracer.render(); 50 51 printRenderTime(timer.lap()); 52 53 try img.writeToFilePath(build_options.output, .{ .png = .{} }); 54 std.log.info("Image saved to: {s}", .{build_options.output}); 55} 56 57fn printRenderTime(t: u64) void { 58 var rt = t; 59 60 const days = rt / std.time.ns_per_day; 61 rt = rt - (days * std.time.ns_per_day); 62 63 const hours = rt / std.time.ns_per_hour; 64 rt = rt - (hours * std.time.ns_per_hour); 65 66 const minutes = rt / std.time.ns_per_min; 67 rt = rt - (minutes * std.time.ns_per_min); 68 69 const seconds = rt / std.time.ns_per_s; 70 rt = rt - (seconds * std.time.ns_per_s); 71 72 const ms = rt / std.time.ns_per_ms; 73 rt = rt - (ms * std.time.ns_per_ms); 74 75 // std.log.info("Image rendered ({}s)", .{rendering_time / std.time.ns_per_s}); 76 if (days == 0) { 77 std.log.info("Image rendered in: {}h {}m {}s {}ms", .{ hours, minutes, seconds, ms }); 78 } else { 79 std.log.info("Image rendered in: {}d {}h {}m {}s {}ms", .{ days, hours, minutes, seconds, ms }); 80 } 81}