this repo has no description
0
fork

Configure Feed

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

go brrrrr

Altagos 99607ee3 f434c300

+15 -81
-6
build.zig
··· 4 4 const target = b.standardTargetOptions(.{}); 5 5 const optimize = b.standardOptimizeOption(.{}); 6 6 7 - // const enable_spall = b.option(bool, "enable_spall", "Enable spall profiling") orelse false; 8 - // const spall = b.dependency("spall", .{ 9 - // .enable = enable_spall, 10 - // }); 11 - 12 7 const options = b.addOptions(); 13 8 14 9 const strip = b.option(bool, "strip", "") orelse (optimize != .Debug); ··· 33 28 }); 34 29 exe.root_module.strip = strip; 35 30 36 - // addDeps(b, &exe.root_module); 37 31 exe.root_module.addImport("rayray", rayray); 38 32 39 33 const alib = b.dependency("a", .{
results/balls-2.png

This is a binary file and will not be displayed.

+5 -2
src/AABB.zig
··· 45 45 } 46 46 47 47 pub fn hit(self: *AABB, r: *Ray, ray_t: Interval) bool { 48 + if (ray_t.max <= ray_t.min) return false; 49 + 48 50 const ray_orig = r.orig; 49 51 const ray_dir = r.dir; 50 52 51 53 var t = ray_t; 52 54 53 - for (0..3) |axis| { 55 + var axis: u8 = 0; 56 + while (axis < 3) : (axis += 1) { 54 57 const ax = self.axisInterval(@intCast(axis)); 55 58 const adinv = 1.0 / ray_dir[axis]; 56 59 ··· 65 68 if (t0 < t.max) t.max = t0; 66 69 } 67 70 68 - if (ray_t.max <= ray_t.min) return false; 71 + if (t.max <= t.min) return false; 69 72 } 70 73 71 74 return true;
+2 -55
src/BVH.zig
··· 18 18 bbox: AABB = AABB{}, 19 19 20 20 pub fn hit(self: *Ast, r: *Ray, ray_t: IntervalF32) ?HitRecord { 21 - if (!self.bbox.hit(r, ray_t)) return null; 21 + // if (!self.bbox.hit(r, ray_t)) return null; 22 22 23 23 var rec: ?HitRecord = null; 24 24 var interval = ray_t; ··· 130 130 } 131 131 132 132 pub inline fn hit(self: *Node, r: *Ray, ray_t: IntervalF32) ?HitRecord { 133 - // if (@constCast(&self.bbox()).hit(r, ray_t)) { 134 - 135 - // } 136 - 137 133 switch (self.*) { 138 134 inline else => |*n| if (n.bbox.hit(r, ray_t)) { 139 135 return n.hit(r, ray_t); ··· 142 138 }, 143 139 } 144 140 } 145 - 146 - fn recomputeBbox(self: *Node) AABB { 147 - switch (self.*) { 148 - .leaf => |*l| return l.bbox, 149 - .ast => |*a| { 150 - var left = AABB{}; 151 - var right = AABB{}; 152 - 153 - if (a.left) |l| left = l.recomputeBbox(); 154 - if (a.right) |r| right = r.recomputeBbox(); 155 - 156 - a.bbox = AABB.initAB(&left, &right); 157 - return a.bbox; 158 - }, 159 - } 160 - } 161 - 162 - pub fn print(self: *Node, depth: usize, side: u8) void { 163 - for (0..depth) |_| std.debug.print(" ", .{}); 164 - 165 - switch (self.*) { 166 - .ast => |*a| { 167 - if (side == 1) { 168 - std.debug.print("Left = ", .{}); 169 - } else if (side >= 2) { 170 - std.debug.print("Right = ", .{}); 171 - } 172 - 173 - std.debug.print("Ast\n", .{}); 174 - 175 - if (a.left) |left| left.print(depth + 1, 1); 176 - if (a.right) |right| right.print(depth + 1, 2); 177 - }, 178 - .leaf => |*l| std.debug.print("Leafs = {}\n", .{l}), 179 - } 180 - } 181 - 182 - fn combineBbox(self: *Node) void { 183 - var left = AABB{}; 184 - var right = AABB{}; 185 - 186 - if (self.left) |l| left = l.bbox; 187 - if (self.right) |r| right = r.bbox; 188 - 189 - self.bbox = AABB.initAB(&left, &right); 190 - } 191 141 }; 192 142 193 143 allocator: std.mem.Allocator, 194 144 root: *Node, 195 - bbox: AABB, 196 145 197 146 pub fn init(allocator: std.mem.Allocator, objects: hittable.HittableList, max_depth: usize) !BVH { 198 147 defer @constCast(&objects).deinit(); ··· 200 149 201 150 const root = try allocator.create(Node); 202 151 try root.init(allocator, objects.list.items, max_depth, 0); 203 - const bbox = root.recomputeBbox(); 152 + // const bbox = root.recomputeBbox(); 204 153 205 154 log.debug("Reached depth of: {}, max objects: {}", .{ reached_depth, max_objects }); 206 155 207 - // root.print(0, 0); 208 156 return .{ 209 157 .allocator = allocator, 210 158 .root = root, 211 - .bbox = bbox, 212 159 }; 213 160 } 214 161
+3 -14
src/hittable/sphere.zig
··· 41 41 } 42 42 43 43 pub inline fn boundingBox(self: *Sphere) AABB { 44 - // if (self.bbox) |bbox| { 45 44 return self.bbox; 46 - // } else { 47 - // const rvec = zm.f32x4s(self.radius); 48 - // self.bbox = AABB.initP(self.center - rvec, self.center + rvec); 49 - // return self.bbox.?; 50 - // } 51 45 } 52 46 53 47 pub fn hit(self: *const Sphere, r: *Ray, ray_t: IntervalF32) ?HitRecord { 54 - const center = blk: { 55 - if (self.is_moving) { 56 - break :blk self.sphereCenter(r.tm); 57 - } else { 58 - break :blk self.center; 59 - } 60 - }; 48 + const center = self.sphereCenter(r.tm); 61 49 const oc = r.orig - center; 62 50 const a = zm.lengthSq3(r.dir)[0]; 63 51 const half_b = zm.dot3(oc, r.dir)[0]; ··· 66 54 const discriminant = half_b * half_b - a * c; 67 55 if (discriminant < 0) return null; 68 56 69 - const sqrtd = zm.sqrt(discriminant); 57 + const sqrtd = @sqrt(discriminant); 70 58 71 59 // Find the nearest root that lies in the acceptable range 72 60 var root = (-half_b - sqrtd) / a; ··· 88 76 } 89 77 90 78 pub inline fn sphereCenter(self: *const Sphere, time: f32) zm.Vec { 79 + if (!self.is_moving) return self.center; 91 80 return self.center + zm.f32x4s(time) * self.center_vec; 92 81 }
+1 -1
src/rayray.zig
··· 71 71 const num_threads = blk: { 72 72 const count = try std.Thread.getCpuCount(); 73 73 if (count > 1) { 74 - break :blk count - 1; 74 + break :blk count; 75 75 } else break :blk 1; 76 76 }; 77 77
+3 -3
src/scences/in_one_weekend.zig
··· 17 17 material_ground.* = Material.lambertian(zm.f32x4(0.5, 0.5, 0.5, 1.0)); 18 18 try world.add(Hittable.sphere("Ground", Sphere.init(zm.f32x4(0, -1000, 0, 0), 1000, material_ground))); 19 19 20 - const a_max = 50; 21 - const b_max = 50; 22 - const c = 3.0; 20 + const a_max = 30; 21 + const b_max = 30; 22 + const c = 1.7; 23 23 24 24 var a: isize = -a_max; 25 25 while (a < a_max) : (a += 1) {
+1
src/tracer.zig
··· 50 50 var width_iter = ctx.width.iter(); 51 51 while (width_iter.nextExc()) |i| { 52 52 var col = zm.f32x4(0.0, 0.0, 0.0, 1.0); 53 + 53 54 for (0..ctx.cam.samples_per_pixel) |_| { 54 55 var ray = ctx.cam.getRay(i, j); 55 56 col += rayColor(&ray, ctx.world, ctx.cam.max_depth);