this repo has no description
0
fork

Configure Feed

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

small changes

Altagos b2b7b046 98b990b0

+20 -15
+1 -1
src/BVH.zig
··· 155 155 self.root.deinit(self.allocator); 156 156 } 157 157 158 - pub inline fn hit(self: *BVH, r: *Ray, ray_t: IntervalF32) ?HitRecord { 158 + pub inline fn hit(self: *const BVH, r: *Ray, ray_t: IntervalF32) ?HitRecord { 159 159 return self.root.hit(r, ray_t); 160 160 } 161 161
+3 -3
src/Camera.zig
··· 155 155 self.image.deinit(); 156 156 } 157 157 158 - pub fn getRay(self: *Camera, i: usize, j: usize) Ray { 158 + pub fn getRay(self: *const Camera, i: usize, j: usize) Ray { 159 159 const offset = sampleSquare(); 160 160 const pixel_sample = self.pixel00_loc + 161 161 (zm.f32x4s(@as(f32, @floatFromInt(i)) + offset[0]) * self.pixel_delta_u) + ··· 172 172 return zm.f32x4(util.randomF32() - 0.5, util.randomF32() - 0.5, 0, 0); 173 173 } 174 174 175 - fn defocusDiskSample(self: *Camera) zm.Vec { 175 + fn defocusDiskSample(self: *const Camera) zm.Vec { 176 176 const p = util.randomInUnitDisk(); 177 177 return self.center + (zm.f32x4s(p[0]) * self.defocus_disk_u) + (zm.f32x4s(p[1]) * self.defocus_disk_v); 178 178 } ··· 183 183 self.image.pixels.rgba32[i] = c; 184 184 } 185 185 186 - fn pixelSamplesSq(self: *Camera) zm.Vec { 186 + fn pixelSamplesSq(self: *const Camera) zm.Vec { 187 187 const px = zm.f32x4s(-0.5 + random.float(f32)); 188 188 const py = zm.f32x4s(-0.5 + random.float(f32)); 189 189 return (px * self.pixel_delta_u) + (py * self.pixel_delta_v);
+3 -2
src/main.zig
··· 1 1 const std = @import("std"); 2 + const Options = std.Options; 2 3 3 4 const aa = @import("a"); 4 5 ··· 11 12 12 13 const scenes = @import("scenes.zig"); 13 14 14 - pub const std_options = .{ 15 + pub const std_options = Options{ 15 16 .log_level = .debug, 16 17 .logFn = aa.log.logFn, 17 18 }; ··· 33 34 var scene = rayray.Scene.init(allocator); 34 35 defer scene.deinit(); 35 36 36 - try scenes.inOneWeekend(&scene); 37 + try scenes.checker(&scene); 37 38 38 39 std.log.info("World created", .{}); 39 40
+1 -1
src/material.zig
··· 25 25 const material = try alloc.create(Material); 26 26 27 27 switch (@TypeOf(data)) { 28 - Metal => material.* = .{ .metal = data }, 28 + Metal => material.* = @unionInit(Material, "metal", data), 29 29 Dielectric => material.* = .{ .dielectric = data }, 30 30 31 31 Lambertian => material.* = .{ .lambertian = data },
+6 -2
src/rayray.zig
··· 119 119 const c_height = IntervalUsize{ .min = row, .max = row + chunk_height }; 120 120 const c_width = IntervalUsize{ .min = col, .max = col + chunk_width + 1 }; 121 121 122 - const ctx = tracer.Context{ 122 + const ctx = try self.allocator.create(tracer.Context); 123 + 124 + // FIXME: might cause the segfault 125 + // possible fix: pass a pointer to the context as argument (create via allocator) 126 + ctx.* = tracer.Context{ 123 127 .pixels = pixels, 124 128 .cam = &self.scene.camera, 125 129 .world = &world_bvh, ··· 210 214 } 211 215 }; 212 216 213 - pub fn renderThread(ctx: tracer.Context, task: *TaskTracker) void { 217 + pub fn renderThread(ctx: *tracer.Context, task: *TaskTracker) void { 214 218 defer task.done.store(true, .release); 215 219 task.thread_id = std.Thread.getCurrentId(); 216 220 tracer.trace(ctx);
+6 -6
src/tracer.zig
··· 19 19 20 20 pub const Context = struct { 21 21 pixels: []zm.Vec, 22 - cam: *Camera, 23 - world: *BVH, 22 + cam: *const Camera, 23 + world: *const BVH, 24 24 height: IntervalUsize, 25 25 width: IntervalUsize, 26 26 }; ··· 28 28 const white = zm.f32x4s(1.0); 29 29 const black = zm.f32x4(0, 0, 0, 1.0); 30 30 31 - pub fn rayColor(r: *Ray, world: *BVH, depth: usize) zm.Vec { 31 + pub fn rayColor(r: *Ray, world: *const BVH, depth: usize) zm.Vec { 32 32 @setFloatMode(.optimized); 33 33 if (depth == 0) return backgroundColor(r); 34 34 ··· 48 48 return zm.f32x4s(1.0 - a) * zm.f32x4s(1.0) + zm.f32x4s(a) * zm.f32x4(0.5, 0.7, 1.0, 1.0); 49 49 } 50 50 51 - pub fn trace(ctx: Context) void { 51 + pub fn trace(ctx: *Context) void { 52 52 var height_iter = ctx.height.iter(); 53 53 while (height_iter.nextInc()) |j| { 54 54 if (j >= ctx.cam.image_height) break; ··· 89 89 ); 90 90 } 91 91 92 - pub fn setPixel(pixels: []zm.Vec, cam: *Camera, x: usize, y: usize, c: zm.Vec) !void { 92 + pub fn setPixel(pixels: []zm.Vec, cam: *const Camera, x: usize, y: usize, c: zm.Vec) !void { 93 93 if (x >= cam.image_width or y >= cam.image_height) return error.OutOfBounds; 94 94 const i = x + cam.image_width * y; 95 95 pixels[i] = c; 96 - try cam.setPixel(x, y, vecToRgba(c, cam.samples_per_pixel_v)); 96 + // try cam.setPixel(x, y, vecToRgba(c, cam.samples_per_pixel_v)); 97 97 }