this repo has no description
0
fork

Configure Feed

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

set max depth

Altagos abc23c36 c8a23603

+29 -15
+13 -8
src/BVH.zig
··· 16 16 bbox: AABB = AABB{}, 17 17 18 18 pub fn hit(self: *Ast, r: *Ray, ray_t: IntervalF32) ?HitRecord { 19 + if (!self.bbox.hit(r, ray_t)) return null; 20 + 19 21 var rec: ?HitRecord = null; 20 22 var interval = ray_t; 21 23 if (self.left) |left| { ··· 129 131 } 130 132 131 133 pub inline fn hit(self: *Node, r: *Ray, ray_t: IntervalF32) ?HitRecord { 132 - if (!@constCast(&self.bbox()).hit(r, ray_t)) { 133 - return null; 134 - } 134 + // if (@constCast(&self.bbox()).hit(r, ray_t)) { 135 + 136 + // } 135 137 136 138 switch (self.*) { 137 - inline else => |*n| return n.hit(r, ray_t), 139 + inline else => |*n| if (n.bbox.hit(r, ray_t)) { 140 + return n.hit(r, ray_t); 141 + } else { 142 + return null; 143 + }, 138 144 } 139 145 } 140 146 ··· 212 218 } 213 219 214 220 pub inline fn hit(self: *BVH, r: *Ray, ray_t: IntervalF32) ?HitRecord { 215 - if (!self.bbox.hit(r, ray_t)) { 216 - return null; 221 + if (self.bbox.hit(r, ray_t)) { 222 + return self.root.hit(r, ray_t); 217 223 } 218 224 219 - return self.root.hit(r, ray_t); 225 + return null; 220 226 } 221 227 222 228 inline fn boxCompare(a: *Hittable, b: *Hittable, axis_index: i32) bool { 223 - @setFloatMode(std.builtin.FloatMode.optimized); 224 229 const a_axis_interval = a.boundingBox().axisInterval(axis_index); 225 230 const b_axis_interval = b.boundingBox().axisInterval(axis_index); 226 231 return a_axis_interval.min < b_axis_interval.min;
+13 -5
src/rayray.zig
··· 1 1 const std = @import("std"); 2 + const build_options = @import("build-options"); 2 3 3 4 pub const zmath = @import("zmath"); 4 5 ··· 40 41 .allocator = allocator, 41 42 .thread_pool = thread_pool, 42 43 .camera = try Camera.init(allocator, camera_opts), 43 - .world = try BVH.init(allocator, world, 100), 44 + .world = try BVH.init(allocator, world, build_options.max_depth), 44 45 }; 45 46 } 46 47 ··· 71 72 72 73 const num_chunks = cols * rows; 73 74 75 + const num_threads = blk: { 76 + const count = try std.Thread.getCpuCount(); 77 + if (count > 1) { 78 + break :blk count - 1; 79 + } else break :blk 1; 80 + }; 81 + 74 82 log.debug("rows: {}, cols: {}, chunk_height: {}, chunk_width: {}, num_chunks: {}, num_threads: {}", .{ 75 83 rows, 76 84 cols, 77 85 chunk_height, 78 86 chunk_width, 79 87 num_chunks, 80 - self.thread_pool.threads.len, 88 + num_threads, 81 89 }); 82 90 83 91 const tasks = try self.allocator.alloc(TaskTracker, num_chunks); ··· 113 121 // node.setCompletedItems(0); 114 122 // node.context.refresh(); 115 123 116 - const num_threads = try std.Thread.getCpuCount(); 117 124 var thread_to_idx = std.ArrayList(std.Thread.Id).init(self.allocator); 118 125 defer thread_to_idx.deinit(); 119 126 120 127 var root_node = std.Progress.start(.{ 121 128 .root_name = "Ray Tracer", 122 - .estimated_total_items = num_threads, 129 + .estimated_total_items = num_chunks, 123 130 }); 124 131 var nodes = std.ArrayList(std.Progress.Node).init(self.allocator); 125 132 defer nodes.deinit(); ··· 151 158 nodes.items[idx].completeOne(); 152 159 153 160 completed_chunks += 1; 154 - if (completed_chunks % self.thread_pool.threads.len == 0) try self.camera.image.writeToFilePath("./out/out.png", .{ .png = .{} }); 161 + root_node.setCompletedItems(completed_chunks); 162 + // if (completed_chunks % self.thread_pool.threads.len == 0) try self.camera.image.writeToFilePath("./out/out.png", .{ .png = .{} }); 155 163 } else if (!task_done) { 156 164 done = false; 157 165 }
+3 -2
src/scences/in_one_weekend.zig
··· 19 19 20 20 const a_max = 50; 21 21 const b_max = 50; 22 + const c = 3.0; 22 23 23 24 var a: isize = -a_max; 24 25 while (a < a_max) : (a += 1) { ··· 26 27 while (b < b_max) : (b += 1) { 27 28 const choose_mat = rayray.util.randomF32(); 28 29 const center = zm.f32x4( 29 - @as(f32, @floatFromInt(a)) + 0.9 * rayray.util.randomF32(), 30 + @as(f32, @floatFromInt(a)) / c + 0.9 * rayray.util.randomF32(), 30 31 0.2, 31 - @as(f32, @floatFromInt(b)) + 0.9 * rayray.util.randomF32(), 32 + @as(f32, @floatFromInt(b)) / c + 0.9 * rayray.util.randomF32(), 32 33 0, 33 34 ); 34 35