add metal fuzziness
This commit is contained in:
parent
c842fcf713
commit
a596058a0d
|
@ -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,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue