this repo has no description
0
fork

Configure Feed

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

fuzzy metal

Altagos 512b5c91 289748fc

+8 -5
+2 -2
src/main.zig
··· 29 29 // Setting up the world 30 30 var material_ground = Material.lambertian(zm.f32x4(0.8, 0.8, 0.0, 1.0)); 31 31 var material_center = Material.lambertian(zm.f32x4(0.7, 0.3, 0.3, 1.0)); 32 - var material_left = Material.metal(zm.f32x4(0.8, 0.8, 0.8, 1.0)); 33 - var material_right = Material.metal(zm.f32x4(0.8, 0.6, 0.2, 1.0)); 32 + var material_left = Material.metal(zm.f32x4(0.8, 0.8, 0.8, 1.0), 0.3); 33 + var material_right = Material.metal(zm.f32x4(0.8, 0.6, 0.2, 1.0), 1.0); 34 34 35 35 var world = HittableList.init(allocator); 36 36 try world.add(Hittable.initSphere(Sphere{ .center = zm.f32x4(0, -100.5, -1, 0), .radius = 100, .mat = &material_ground }));
+6 -3
src/material.zig
··· 12 12 return .{ .lambertian = .{ .albedo = albedo } }; 13 13 } 14 14 15 - pub fn metal(albedo: zm.Vec) Material { 16 - return .{ .metal = .{ .albedo = albedo } }; 15 + pub fn metal(albedo: zm.Vec, fuzz: f32) Material { 16 + return .{ .metal = .{ .albedo = albedo, .fuzz = if (fuzz < 1) fuzz else 1.0 } }; 17 17 } 18 18 19 19 pub fn scatter(self: *Material, r: *Ray, rec: *hittable.HitRecord, attenuation: *zm.Vec) ?Ray { ··· 39 39 40 40 pub const Metal = struct { 41 41 albedo: zm.Vec, 42 + /// fuzz < 1 43 + fuzz: f32, 42 44 43 45 pub fn scatter(self: *Metal, r: *Ray, rec: *hittable.HitRecord, attenuation: *zm.Vec) ?Ray { 44 46 const reflected = util.reflect(zm.normalize3(r.dir), rec.normal); 47 + const scattered = Ray.init(rec.p, reflected + zm.f32x4s(self.fuzz) * util.randomUnitVec()); 45 48 attenuation.* = self.albedo; 46 - return Ray.init(rec.p, reflected); 49 + return if (zm.dot3(scattered.dir, rec.normal)[0] > 0) scattered else null; 47 50 } 48 51 };