New scatter formula
This commit is contained in:
parent
f252823b4b
commit
2e24fef5ac
2 changed files with 17 additions and 1 deletions
2
main.cpp
2
main.cpp
|
|
@ -21,7 +21,7 @@ color ray_color(const ray& r, const hittable& world, int32_t depth)
|
||||||
hit_record rec;
|
hit_record rec;
|
||||||
if (world.hit(r, 0.001, INFINITY, rec))
|
if (world.hit(r, 0.001, INFINITY, rec))
|
||||||
{
|
{
|
||||||
point3 target = rec.p + rec.normal + random_in_unit_sphere();
|
point3 target = rec.p + rec.normal + random_in_hemisphere(rec.normal);
|
||||||
return 0.5 * ray_color(ray(rec.p, target - rec.p), world, depth-1);
|
return 0.5 * ray_color(ray(rec.p, target - rec.p), world, depth-1);
|
||||||
}
|
}
|
||||||
vec3 unit_direction = normalize(r.direction);
|
vec3 unit_direction = normalize(r.direction);
|
||||||
|
|
|
||||||
16
vec3.hpp
16
vec3.hpp
|
|
@ -159,4 +159,20 @@ vec3 random_in_unit_sphere()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a normalized version of the above vector
|
||||||
|
vec3 random_unit_vector()
|
||||||
|
{
|
||||||
|
return normalize(random_in_unit_sphere());
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 random_in_hemisphere(const vec3& normal)
|
||||||
|
{
|
||||||
|
vec3 in_unit_sphere = random_in_unit_sphere();
|
||||||
|
|
||||||
|
if (dot(in_unit_sphere, normal) > 0.0)
|
||||||
|
return in_unit_sphere;
|
||||||
|
else
|
||||||
|
return -in_unit_sphere;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue