1
0

fix: change to a hemisphere diffuse method

This commit is contained in:
Rokas Puzonas 2022-03-13 19:47:07 +02:00
parent 497bb5776c
commit cd414d1aeb
3 changed files with 66227 additions and 66215 deletions

132424
image.ppm

File diff suppressed because it is too large Load Diff

View File

@ -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
View File

@ -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