add metal fuzziness

This commit is contained in:
Fabien Freling 2021-05-27 21:28:14 +02:00
parent c842fcf713
commit a596058a0d
2 changed files with 8 additions and 6 deletions

View file

@ -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,
}
};

View file

@ -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;
}