-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non skip pdf in lights HittableList #1668
Comments
I' ve looked into it a bit and found out that what's causing the problem is the sphere part of the HittablePDF list belonging to lights: // main.cpp
HittableList lights;
lights.add(std::make_shared<Quad>(Vec3(213, 554, 227), Vec3(130, 0, 0), Vec3(0, 0, 105), empty_mat));
lights.add(std::make_shared<Sphere>(Vec3(190, 90, 190), 90, empty_mat)); if i select just the sphere part // camera.cpp
Color color_from_scatter = Color();
for (const auto& ray_t : srec.scattered_rays) {
if (ray_t.skip_pdf || ray_t.pdf == nullptr) {
color_from_scatter += ray_t.attenuation * ray_color(ray_t.skip_pdf_ray, depth-1, world, lights);
} else {
auto light_ptr = std::make_shared<HittablePDF>(lights, rec.point()); // lights is the problematic part
MixturePDF p(light_ptr, ray_t.pdf);
Ray scattered = Ray(rec.point(), p.generate(), r.time());
double pdf_value = p.value(scattered.direction(), r.direction(), -w);
double scattering_pdf = rec.material()->scattering_pdf(r, rec, scattered, -w);
Color sample_color = ray_color(scattered, depth-1, world, lights);
color_from_scatter += (ray_t.attenuation * scattering_pdf * sample_color) / pdf_value;
}
} // hittable.pdf
double HittableList::pdf_value(const Vec3& origin, const Vec3& direction) const {
auto weight = 1.0 / objects.size();
double sum{};
for (const auto& obj : objects) {
sum += weight * obj->pdf_value(origin, direction);
}
//return sum;
return objects[1]->pdf_value(origin, direction);
}
Vec3 HittableList::random(const Vec3& origin) const {
auto int_size = int(objects.size());
//return objects[random_int(0, int_size-1)]->random(origin);
return objects[1]->random(origin);
} i get while e.g. with only the light part (index 0) i get a decent image by comparison, excluding the sphere from the lights list i get By checking some values between
but adding some temporary control like Vec3 HittableList::random(const Vec3& origin) const {
auto int_size = int(objects.size());
auto vec = objects[random_int(0, int_size-1)]->random(origin);
while (vec.is_nan()) {
vec = objects[random_int(0, int_size-1)]->random(origin);
}
return vec;
} // vector.h
bool is_nan() const {
return std::isnan(e[0]) || std::isnan(e[1]) || std::isnan(e[2]);
} had no change, so this does not seem to be the problem. |
Thank you for grinding on this! |
Hello, i went back to the problem and managed to solve it by adding a control to the sampling of the sphere and the previously mentioned for the double pdf_value(const point3& origin, const vec3& direction) const override {
// This method only works for stationary spheres.
hit_record rec;
if (!this->hit(ray(origin, direction), interval(0.001, infinity), rec))
return 0;
auto cos_theta_max = sqrt(1 - radius*radius/(center.at(0) - origin).length_squared());
auto solid_angle = 2*pi*(1-cos_theta_max);
if (std::isnan(solid_angle) || std::fabs(solid_angle) < 1e-3) {
return 0;
} else {
return 1 / solid_angle;
}
} Now the image does not turn black when a "pdf type" material (e.g. lambertians) are added to the I'm including some images that shows the cornell box with and without the sphere in the lights list: with As you can see the sphere is better highlighted, although there are some black pixels, a thing that i actually don't see in my own implementation, so there might be something else behind it image from my repo I' ve opened a draft pull request #1674 in case you are interested, it would be great to contribute to the project even a little bit! In case tell me if i should close this issue. |
Hello, if i add to the lights list an object that is not a metal or dielectric the image produced is like
i' ve obtained this by putting
in the main.cpp of therestofyourlife part.
I may not have understood correctly this part of the code and thus it may not be an actual issue but still i wanted to ask this since also a material like a lambertian is still emitting some reflected light
The text was updated successfully, but these errors were encountered: