From a596058a0dcd4da7fac7a0199865def47aab1e66 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 27 May 2021 21:28:14 +0200 Subject: [PATCH] add metal fuzziness --- in_one_weekend/src/main.zig | 10 ++++++---- in_one_weekend/src/material.zig | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/in_one_weekend/src/main.zig b/in_one_weekend/src/main.zig index 656f66b..57c718a 100644 --- a/in_one_weekend/src/main.zig +++ b/in_one_weekend/src/main.zig @@ -93,22 +93,24 @@ pub fn main() anyerror!void { // World const materialGround = Material{ .lambertian = material.Lambertian{ - .color = Color{ .x = 0.8, .y = 0.8, .z = 0.0 } + .color = Color{ .x = 0.8, .y = 0.8, .z = 0.0 }, } }; const materialCenter = Material{ .lambertian = material.Lambertian{ - .color = Color{ .x = 0.7, .y = 0.3, .z = 0.3 } + .color = Color{ .x = 0.7, .y = 0.3, .z = 0.3 }, } }; const materialLeft = Material{ .metal = material.Metal{ - .color = Color{ .x = 0.8, .y = 0.8, .z = 0.8 } + .color = Color{ .x = 0.8, .y = 0.8, .z = 0.8 }, + .fuzz = 0.3, } }; const materialRight = Material{ .metal = material.Metal{ - .color = Color{ .x = 0.8, .y = 0.6, .z = 0.2 } + .color = Color{ .x = 0.8, .y = 0.6, .z = 0.2 }, + .fuzz = 1.0, } }; diff --git a/in_one_weekend/src/material.zig b/in_one_weekend/src/material.zig index 95edca2..9286c15 100644 --- a/in_one_weekend/src/material.zig +++ b/in_one_weekend/src/material.zig @@ -29,11 +29,11 @@ pub const Lambertian = struct { pub const Metal = struct { color: Color, - // fuzzy: f32, + fuzz: f32, pub fn scatter(self: Metal, ray: Ray, hit: HitRecord, rng: *Random) ?ScatteredRay { const reflected = ray.direction.unit().reflect(hit.normal); - const scattered = Ray{ .origin = hit.p, .direction = reflected }; + const scattered = Ray{ .origin = hit.p, .direction = reflected.add(vec3.random_in_unit_sphere(rng).mul_s(self.fuzz)) }; if (scattered.direction.dot(hit.normal) <= 0) { return null; }