this repo has no description

cleanup

+29 -32
+5 -17
build.zig
··· 28 exe.root_module.addImport("spall", spall.module("spall")); 29 exe.root_module.addImport("rayray", rayray); 30 31 - const alib = b.dependency("a", .{ 32 - .target = target, 33 - .optimize = optimize, 34 - .log_ignore_default = true, 35 - }); 36 - 37 - exe.root_module.addImport("a", alib.module("a")); 38 - 39 b.installArtifact(exe); 40 41 const run_cmd = b.addRunArtifact(exe); ··· 47 48 const run_step = b.step("run", "Run the app"); 49 run_step.dependOn(&run_cmd.step); 50 - 51 - const lib_unit_tests = b.addTest(.{ 52 - .root_source_file = .{ .path = "src/root.zig" }, 53 - .target = target, 54 - .optimize = optimize, 55 - }); 56 - const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); 57 - const test_step = b.step("test", "Run unit tests"); 58 - test_step.dependOn(&run_lib_unit_tests.step); 59 } 60 61 fn addDeps(b: *std.Build, module: *std.Build.Module) void { 62 const zmath = b.dependency("zmath", .{ 63 .enable_cross_platform_determinism = true, 64 });
··· 28 exe.root_module.addImport("spall", spall.module("spall")); 29 exe.root_module.addImport("rayray", rayray); 30 31 b.installArtifact(exe); 32 33 const run_cmd = b.addRunArtifact(exe); ··· 39 40 const run_step = b.step("run", "Run the app"); 41 run_step.dependOn(&run_cmd.step); 42 } 43 44 fn addDeps(b: *std.Build, module: *std.Build.Module) void { 45 + const alib = b.dependency("a", .{ 46 + .log_ignore_default = true, 47 + }); 48 + module.addImport("a", alib.module("a")); 49 + 50 const zmath = b.dependency("zmath", .{ 51 .enable_cross_platform_determinism = true, 52 });
+2
src/hittable.zig
··· 4 5 const IntervalF32 = @import("interval.zig").IntervalF32; 6 const Ray = @import("ray.zig"); 7 pub const Sphere = @import("hittable/sphere.zig"); 8 9 pub const HitRecord = struct {
··· 4 5 const IntervalF32 = @import("interval.zig").IntervalF32; 6 const Ray = @import("ray.zig"); 7 + 8 + // Hittable Objects 9 pub const Sphere = @import("hittable/sphere.zig"); 10 11 pub const HitRecord = struct {
+10
src/interval.zig
··· 54 return self.current; 55 } else return null; 56 } 57 }; 58 59 min: T,
··· 54 return self.current; 55 } else return null; 56 } 57 + 58 + pub fn nextInc(self: *Iterator) ?T { 59 + self.current += 1; 60 + return if (self.current <= self.interval.max) self.current else null; 61 + } 62 + 63 + pub fn nextExc(self: *Iterator) ?T { 64 + self.current += 1; 65 + return if (self.current < self.interval.max) self.current else null; 66 + } 67 }; 68 69 min: T,
+5 -1
src/main.zig
··· 25 spall.init_thread(); 26 defer spall.deinit_thread(); 27 28 var world = HittableList.init(allocator); 29 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(0, 0, -1, 0), .radius = 0.5 })); 30 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(0, -100.5, -1, 0), .radius = 100 })); 31 32 - const s = spall.trace(@src(), "Main", .{}); 33 34 var raytracer = try rayray.Raytracer.init(allocator, world); 35 defer raytracer.deinit(); 36 ··· 39 40 s.end(); 41 42 const s_saving = spall.trace(@src(), "Write Image", .{}); 43 defer s_saving.end(); 44 try img.writeToFilePath("./out/out.png", .{ .png = .{} }); 45 std.log.info("Image saved to: out/out.ong", .{}); 46 }
··· 25 spall.init_thread(); 26 defer spall.deinit_thread(); 27 28 + // Setting up the world 29 var world = HittableList.init(allocator); 30 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(0, 0, -1, 0), .radius = 0.5 })); 31 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(0, -100.5, -1, 0), .radius = 100 })); 32 33 + const s = spall.trace(@src(), "Raytracer", .{}); 34 35 + // Raytracing part 36 var raytracer = try rayray.Raytracer.init(allocator, world); 37 defer raytracer.deinit(); 38 ··· 41 42 s.end(); 43 44 + // Saving to file 45 const s_saving = spall.trace(@src(), "Write Image", .{}); 46 defer s_saving.end(); 47 + 48 try img.writeToFilePath("./out/out.png", .{ .png = .{} }); 49 std.log.info("Image saved to: out/out.ong", .{}); 50 }
-1
src/rayray.zig
··· 3 const spall = @import("spall"); 4 const zigimg = @import("zigimg"); 5 const color = zigimg.color; 6 - const zm = @import("zmath"); 7 8 pub const Camera = @import("camera.zig"); 9 pub const hittable = @import("hittable.zig");
··· 3 const spall = @import("spall"); 4 const zigimg = @import("zigimg"); 5 const color = zigimg.color; 6 7 pub const Camera = @import("camera.zig"); 8 pub const hittable = @import("hittable.zig");
+7 -13
src/renderer.zig
··· 2 3 const spall = @import("spall"); 4 const zigimg = @import("zigimg"); 5 - const color = zigimg.color; 6 const zm = @import("zmath"); 7 8 pub const Camera = @import("camera.zig"); 9 pub const interval = @import("interval.zig"); 10 pub const IntervalUsize = interval.IntervalUsize; 11 pub const IntervalF32 = interval.IntervalF32; 12 - pub const hittable = @import("hittable.zig"); 13 - pub const Ray = @import("ray.zig"); 14 15 const log = std.log.scoped(.renderer); 16 ··· 31 32 pub fn run(ctx: Context, height: IntervalUsize, width: IntervalUsize) void { 33 var height_iter = height.iter(); 34 - height_iter.upper_boundry = .inclusive; 35 - 36 - while (height_iter.next()) |j| { 37 if (j >= ctx.cam.image_height) break; 38 39 var width_iter = width.iter(); 40 - height_iter.upper_boundry = .inclusive; 41 - 42 - while (width_iter.next()) |i| inner: { 43 - if (i >= ctx.cam.image_width) break :inner; 44 - 45 const pixel_center = ctx.cam.pixel00_loc + (zm.f32x4s(@as(f32, @floatFromInt(i))) * ctx.cam.pixel_delta_u) + (zm.f32x4s(@as(f32, @floatFromInt(j))) * ctx.cam.pixel_delta_v); 46 const ray_direction = pixel_center - ctx.cam.camera_center; 47 var ray = Ray.init(ctx.cam.camera_center, ray_direction); ··· 69 done.store(true, .Release); 70 } 71 72 - fn vecToRgba(v: zm.Vec) color.Rgba32 { 73 const r: u8 = @intFromFloat(255.999 * v[0]); 74 const g: u8 = @intFromFloat(255.999 * v[1]); 75 const b: u8 = @intFromFloat(255.999 * v[2]); 76 const a: u8 = @intFromFloat(255.999 * v[3]); 77 78 - return color.Rgba32.initRgba(r, g, b, a); 79 }
··· 2 3 const spall = @import("spall"); 4 const zigimg = @import("zigimg"); 5 const zm = @import("zmath"); 6 7 pub const Camera = @import("camera.zig"); 8 + pub const hittable = @import("hittable.zig"); 9 + pub const Ray = @import("ray.zig"); 10 + 11 pub const interval = @import("interval.zig"); 12 pub const IntervalUsize = interval.IntervalUsize; 13 pub const IntervalF32 = interval.IntervalF32; 14 15 const log = std.log.scoped(.renderer); 16 ··· 31 32 pub fn run(ctx: Context, height: IntervalUsize, width: IntervalUsize) void { 33 var height_iter = height.iter(); 34 + while (height_iter.nextInc()) |j| { 35 if (j >= ctx.cam.image_height) break; 36 37 var width_iter = width.iter(); 38 + while (width_iter.nextExc()) |i| { 39 const pixel_center = ctx.cam.pixel00_loc + (zm.f32x4s(@as(f32, @floatFromInt(i))) * ctx.cam.pixel_delta_u) + (zm.f32x4s(@as(f32, @floatFromInt(j))) * ctx.cam.pixel_delta_v); 40 const ray_direction = pixel_center - ctx.cam.camera_center; 41 var ray = Ray.init(ctx.cam.camera_center, ray_direction); ··· 63 done.store(true, .Release); 64 } 65 66 + fn vecToRgba(v: zm.Vec) zigimg.color.Rgba32 { 67 const r: u8 = @intFromFloat(255.999 * v[0]); 68 const g: u8 = @intFromFloat(255.999 * v[1]); 69 const b: u8 = @intFromFloat(255.999 * v[2]); 70 const a: u8 = @intFromFloat(255.999 * v[3]); 71 72 + return zigimg.color.Rgba32.initRgba(r, g, b, a); 73 }