fix: change to a hemisphere diffuse method
This commit is contained in:
parent
497bb5776c
commit
cd414d1aeb
6
main.cc
6
main.cc
@ -14,8 +14,8 @@ color ray_color(const ray& r, const hittable& world, int depth) {
|
||||
if (depth <= 0)
|
||||
return color(0, 0, 0);
|
||||
|
||||
if (world.hit(r, 0, infinity, rec)) {
|
||||
point3 target = rec.p + rec.normal + random_in_unit_sphere();
|
||||
if (world.hit(r, 0.001, infinity, rec)) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ int main() {
|
||||
const auto aspect_ratio = 16.0 / 9.0;
|
||||
const int image_width = 400;
|
||||
const int image_height = static_cast<int>(image_width / aspect_ratio);
|
||||
const int samples_per_pixel = 32;
|
||||
const int samples_per_pixel = 16;
|
||||
const int max_depth = 25;
|
||||
|
||||
// World
|
||||
|
12
vec3.h
12
vec3.h
@ -116,4 +116,16 @@ inline vec3 unit_vector(vec3 v) {
|
||||
return v / v.length();
|
||||
}
|
||||
|
||||
vec3 random_unit_vector() {
|
||||
return unit_vector(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) // In thesame hemisphere as the normal
|
||||
return in_unit_sphere;
|
||||
else
|
||||
return -in_unit_sphere;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user