this repo has no description

added a sphere

+13
+13
src/ray.zig
··· 13 } 14 15 pub fn color(self: *Ray) zm.Vec { 16 const unit_direction = zm.normalize3(self.dir); 17 const a = 0.5 * (unit_direction[1] + 1.0); 18 return zm.f32x4s(1.0 - a) * zm.f32x4s(1.0) + zm.f32x4s(a) * zm.f32x4(0.5, 0.7, 1.0, 1.0); 19 }
··· 13 } 14 15 pub fn color(self: *Ray) zm.Vec { 16 + if (hit_sphere(zm.f32x4(0, 0, -1, 0), 0.5, self)) { 17 + return zm.f32x4(1, 0, 0, 1); 18 + } 19 + 20 const unit_direction = zm.normalize3(self.dir); 21 const a = 0.5 * (unit_direction[1] + 1.0); 22 return zm.f32x4s(1.0 - a) * zm.f32x4s(1.0) + zm.f32x4s(a) * zm.f32x4(0.5, 0.7, 1.0, 1.0); 23 } 24 + 25 + fn hit_sphere(center: zm.Vec, radius: f32, r: *Ray) bool { 26 + const oc = r.orig - center; 27 + const a = zm.dot3(r.dir, r.dir)[0]; 28 + const b = 2.0 * zm.dot3(oc, r.dir)[0]; 29 + const c = zm.dot3(oc, oc)[0] - radius * radius; 30 + const discriminant = b * b - 4 * a * c; 31 + return discriminant >= 0; 32 + }