zigrtiow: fix acne

This commit is contained in:
Bill Thiede 2022-08-05 18:31:09 -07:00
parent 58646e4142
commit 6d7998ad9f
2 changed files with 10 additions and 6 deletions

View File

@ -15,6 +15,7 @@ const Point3 = vec.Point3;
const Ray = ray.Ray;
const Sphere = sphere.Sphere;
const Vec3 = vec.Vec3;
const random_unit_vector = vec.random_unit_vector;
const random_in_unit_sphere = vec.random_in_unit_sphere;
const info = std.log.info;
const write_color = color.write_color;
@ -23,10 +24,10 @@ fn ray_color(r: Ray, world: Hittable, depth: isize) Color {
// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0) return Color.init(0, 0, 0);
var hit = world.hit(r, 0, std.math.inf(f32));
var hit = world.hit(r, 0.0001, std.math.inf(f32));
if (hit) |rec| {
const target = rec.p.add(rec.normal.add(random_in_unit_sphere()));
return ray_color(Ray.init(rec.p, target.sub(rec.p)), world, depth - 1);
const target = rec.p.add(rec.normal.add(random_unit_vector()));
return ray_color(Ray.init(rec.p, target.sub(rec.p)), world, depth - 1).scale(0.5);
}
var unit_direction = r.direction().unit();
const t = 0.5 * (unit_direction.y() + 1);

View File

@ -47,9 +47,9 @@ pub const Vec3 = struct {
/// Return value in unit cube from -1, 1
pub fn random() Vec3 {
return Vec3.init(
rand.float(f32) * 2 - 0.5,
rand.float(f32) * 2 - 0.5,
rand.float(f32) * 2 - 0.5,
rand.float(f32) * 2 - 1,
rand.float(f32) * 2 - 1,
rand.float(f32) * 2 - 1,
);
}
};
@ -61,6 +61,9 @@ pub fn random_in_unit_sphere() Vec3 {
return p;
}
}
pub fn random_unit_vector() Vec3 {
return random_in_unit_sphere().unit();
}
pub const Color = Vec3;
pub const Point3 = Vec3;