Add additional scattering methods.
This commit is contained in:
parent
b86ad047a5
commit
267df23c87
2
Makefile
2
Makefile
@ -10,7 +10,7 @@ TARGET = wtracer
|
||||
all: $(TARGET) run
|
||||
|
||||
run:
|
||||
./wtracer > image.ppm
|
||||
time -f '%E elapsed' ./wtracer > image.ppm
|
||||
eog image.ppm
|
||||
|
||||
%.o: %.cpp $(DEPS)
|
||||
|
15
vec3.h
15
vec3.h
@ -120,4 +120,19 @@ Vec3 random_in_unit_sphere() {
|
||||
}
|
||||
}
|
||||
|
||||
Vec3 random_unit_vector() {
|
||||
auto a = random_double(0, 2*pi);
|
||||
auto z = random_double(-1, 1);
|
||||
auto r = std::sqrt(1 - z*z);
|
||||
return Vec3(r*std::cos(a), r*std::sin(a), z);
|
||||
}
|
||||
|
||||
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 // VEC3_H
|
||||
|
@ -15,8 +15,10 @@ 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_unit_sphere();
|
||||
//Point3 target = rec.p + rec.normal + random_unit_vector();
|
||||
Point3 target = rec.p + random_in_hemisphere(rec.normal);
|
||||
return 0.5 * ray_color(Ray(rec.p, target - rec.p), world, depth-1);
|
||||
}
|
||||
Vec3 unit_direction = unit_vector(r.direction());
|
||||
@ -30,7 +32,7 @@ int main() {
|
||||
const int image_width = 768;
|
||||
//const int image_width = 384;
|
||||
const int image_height = static_cast<int>(image_width / aspect_ratio);
|
||||
const int samples_per_pixel = 250;
|
||||
const int samples_per_pixel = 400;
|
||||
const int max_depth = 50;
|
||||
|
||||
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
|
||||
|
Loading…
Reference in New Issue
Block a user