zigrtiow: fix acne
This commit is contained in:
parent
58646e4142
commit
6d7998ad9f
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user