this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cleanup

Altagos 1d0907c1 232ee550

+18 -23
results/balls.png

This is a binary file and will not be displayed.

+5 -9
src/hittable.zig
··· 22 22 } 23 23 }; 24 24 25 - pub const HittableType = enum { 26 - sphere, 27 - }; 28 - 29 - pub const Hittable = union(HittableType) { 25 + pub const Hittable = union(enum) { 30 26 sphere: Sphere, 31 27 32 - pub fn initSphere(sphere: Sphere) Hittable { 33 - return .{ .sphere = sphere }; 28 + pub fn sphere(s: Sphere) Hittable { 29 + return .{ .sphere = s }; 34 30 } 35 31 36 32 pub fn hit(self: *Hittable, r: *Ray, ray_t: IntervalF32) ?HitRecord { 37 33 switch (self.*) { 38 - .sphere => |*sphere| { 39 - return sphere.hit(r, ray_t); 34 + .sphere => |*s| { 35 + return s.hit(r, ray_t); 40 36 }, 41 37 } 42 38
+5 -5
src/main.zig
··· 29 29 // Setting up the world 30 30 var material_ground = Material.lambertian(zm.f32x4(0.8, 0.8, 0.0, 1.0)); 31 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); 32 + var material_left = Material.metal(zm.f32x4(0.8, 0.8, 0.8, 1.0), 0.0); 33 33 var material_right = Material.metal(zm.f32x4(0.8, 0.6, 0.2, 1.0), 1.0); 34 34 35 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 })); 36 + try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(0, -100.5, -1, 0), .radius = 100, .mat = &material_ground })); 37 + try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(0, 0, -1, 0), .radius = 0.5, .mat = &material_center })); 38 + try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(-1, 0, -1, 0), .radius = 0.5, .mat = &material_left })); 39 + try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(1, 0, -1, 0), .radius = 0.5, .mat = &material_right })); 40 40 41 41 const s = spall.trace(@src(), "Raytracer", .{}); 42 42
+7 -8
src/rayray.zig
··· 59 59 var threads = try self.allocator.alloc(ThreadTracker, num_threads); 60 60 defer self.allocator.free(threads); 61 61 62 - const finished_threads = try self.allocator.alloc(bool, num_threads); 63 - 64 62 for (0..num_threads) |row| { 65 63 const ctx = renderer.Context{ .cam = &self.camera, .world = &self.world }; 66 64 const t = try std.Thread.spawn( ··· 82 80 .terminal = stderr, 83 81 .supports_ansi_escape_codes = true, 84 82 }; 85 - var node = progress.start("Rendering", num_threads); 86 - // node.activate(); 83 + var node = progress.start("Rendered Chunks", num_threads); 84 + node.setCompletedItems(0); 87 85 node.context.refresh(); 88 86 89 87 while (true) { 90 88 var done = true; 91 89 92 90 for (0..num_threads) |id| { 93 - if (threads[id].done.load(.Acquire) and !threads[id].marked_as_done) { 91 + const thead_done = threads[id].done.load(.Acquire); 92 + if (thead_done and !threads[id].marked_as_done) { 94 93 threads[id].thread.join(); 95 94 threads[id].marked_as_done = true; 96 - finished_threads[id] = true; 95 + 97 96 node.completeOne(); 98 - } else if (!threads[id].done.load(.Acquire)) { 97 + } else if (!thead_done) { 99 98 done = false; 100 99 } 101 100 } ··· 103 102 if (done) break; 104 103 } 105 104 106 - node.end(); 105 + // node.end(); 107 106 108 107 return self.camera.image; 109 108 }
+1 -1
src/renderer.zig
··· 24 24 pub fn rayColor(r: *Ray, world: *hittable.HittableList, depth: usize) zm.Vec { 25 25 if (depth <= 0) return zm.f32x4(0, 0, 0, 1.0); 26 26 27 - if (world.hit(r, IntervalF32.init(0.001, std.math.inf(f32)))) |rec| { 27 + if (world.hit(r, .{ .min = 0.001, .max = std.math.inf(f32) })) |rec| { 28 28 var attenuation = zm.f32x4s(1.0); 29 29 if (rec.mat.scatter(r, @constCast(&rec), &attenuation)) |new_r| { 30 30 return attenuation * rayColor(@constCast(&new_r), world, depth - 1);