this repo has no description
0
fork

Configure Feed

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

aded time

Altagos 35da41e7 e83a9065

+46 -10
+3 -1
src/camera.zig
··· 161 161 162 162 const ray_orig = if (self.defocus_angle <= 0) self.center else self.defocusDiskSample(); 163 163 const ray_direction = pixel_sample - ray_orig; 164 - return Ray.init(ray_orig, ray_direction); 164 + const ray_time = util.randomF32(); 165 + 166 + return Ray.initT(ray_orig, ray_direction, ray_time); 165 167 } 166 168 167 169 fn sampleSquare() zm.Vec {
+24 -1
src/hittable/sphere.zig
··· 10 10 center: zm.Vec, 11 11 radius: f32, 12 12 mat: *Material, 13 + is_moving: bool = false, 14 + center_vec: zm.Vec = zm.f32x4s(0), 15 + 16 + pub fn initMoving(center1: zm.Vec, center2: zm.Vec, radius: f32, mat: *Material) Sphere { 17 + return .{ 18 + .center = center1, 19 + .radius = @max(0, radius), 20 + .mat = mat, 21 + .is_moving = true, 22 + .center_vec = center2 - center1, 23 + }; 24 + } 13 25 14 26 pub fn hit(self: *Sphere, r: *Ray, ray_t: IntervalF32) ?HitRecord { 15 - const oc = r.orig - self.center; 27 + const center = blk: { 28 + if (self.is_moving) { 29 + break :blk self.sphereCenter(r.tm); 30 + } else { 31 + break :blk self.center; 32 + } 33 + }; 34 + const oc = r.orig - center; 16 35 const a = zm.lengthSq3(r.dir)[0]; 17 36 const half_b = zm.dot3(oc, r.dir)[0]; 18 37 const c = zm.dot3(oc, oc)[0] - self.radius * self.radius; ··· 40 59 41 60 return rec; 42 61 } 62 + 63 + pub fn sphereCenter(self: *Sphere, time: f32) zm.Vec { 64 + return self.center + zm.f32x4s(time) * self.center_vec; 65 + }
+4 -3
src/main.zig
··· 51 51 // diffuse 52 52 const albedo = rayray.util.randomVec3() * rayray.util.randomVec3() + zm.f32x4(0, 0, 0, 1); 53 53 material.* = Material.lambertian(albedo); 54 - try world.add(Hittable.sphere(Sphere{ .center = center, .radius = 0.2, .mat = material })); 54 + const center2 = center + zm.f32x4(0, rayray.util.randomF32M(0, 0.5), 0, 0); 55 + try world.add(Hittable.sphere(Sphere.initMoving(center, center2, 0.2, material))); 55 56 } else if (choose_mat < 0.95) { 56 57 // metal 57 58 const albedo = rayray.util.randomVec3M(0.5, 1) + zm.f32x4(0, 0, 0, 1); ··· 81 82 // Raytracing part 82 83 var raytracer = try rayray.Raytracer.init(allocator, world, .{ 83 84 .aspect_ratio = 16.0 / 9.0, 84 - .image_width = 1200, 85 - .samples_per_pixel = 500, 85 + .image_width = 400, 86 + .samples_per_pixel = 100, 86 87 .max_depth = 50, 87 88 88 89 .vfov = 20,
+5 -5
src/material.zig
··· 25 25 26 26 pub fn scatter(self: *Material, r: *Ray, rec: *hittable.HitRecord, attenuation: *zm.Vec) ?Ray { 27 27 return switch (self.*) { 28 - .lambertian => |*lambert| lambert.scatter(rec, attenuation), 28 + .lambertian => |*lambert| lambert.scatter(r, rec, attenuation), 29 29 .metal => |*met| met.scatter(r, rec, attenuation), 30 30 .dielectric => |*die| die.scatter(r, rec, attenuation), 31 31 }; ··· 35 35 pub const Lambertian = struct { 36 36 albedo: zm.Vec, 37 37 38 - pub fn scatter(self: *Lambertian, rec: *hittable.HitRecord, attenuation: *zm.Vec) ?Ray { 38 + pub fn scatter(self: *Lambertian, r: *Ray, rec: *hittable.HitRecord, attenuation: *zm.Vec) ?Ray { 39 39 var scatter_dir = rec.normal + util.randomUnitVec(); 40 40 41 41 if (util.nearZero(scatter_dir)) scatter_dir = rec.normal; 42 42 43 43 attenuation.* = self.albedo; 44 - return Ray.init(rec.p, scatter_dir); 44 + return Ray.initT(rec.p, scatter_dir, r.tm); 45 45 } 46 46 }; 47 47 ··· 52 52 53 53 pub fn scatter(self: *Metal, r: *Ray, rec: *hittable.HitRecord, attenuation: *zm.Vec) ?Ray { 54 54 const reflected = util.reflect(r.dir, rec.normal); 55 - const scattered = Ray.init(rec.p, zm.normalize3(reflected) + zm.f32x4s(self.fuzz) * util.randomUnitVec()); 55 + const scattered = Ray.initT(rec.p, zm.normalize3(reflected) + zm.f32x4s(self.fuzz) * util.randomUnitVec(), r.tm); 56 56 attenuation.* = self.albedo; 57 57 return if (zm.dot3(scattered.dir, rec.normal)[0] > 0) scattered else null; 58 58 } ··· 78 78 } 79 79 }; 80 80 81 - return Ray.init(rec.p, direction); 81 + return Ray.initT(rec.p, direction, r.tm); 82 82 } 83 83 84 84 fn reflectance(cosine: f32, refraction_index: f32) f32 {
+10
src/ray.zig
··· 6 6 7 7 orig: zm.Vec, 8 8 dir: zm.Vec, 9 + tm: f32, 9 10 10 11 pub fn init(origin: zm.Vec, direction: zm.Vec) Ray { 11 12 return Ray{ 12 13 .orig = origin, 13 14 .dir = direction, 15 + .tm = 0, 16 + }; 17 + } 18 + 19 + pub fn initT(origin: zm.Vec, direction: zm.Vec, tm: f32) Ray { 20 + return Ray{ 21 + .orig = origin, 22 + .dir = direction, 23 + .tm = tm, 14 24 }; 15 25 } 16 26