Skip to content
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

now nonskippdf materials can be added to lights hittable list #1674

Open
wants to merge 1 commit into
base: dev-patch
Choose a base branch
from

Conversation

niccolot
Copy link

@niccolot niccolot commented Feb 6, 2025

Hello, i' ve modified the pdf_value function for the sphere and the random hittable_list method to include controls for NaNs and zero division, now even materials like a lambertian can be added to the lights hittable list. To see the details and the changes refer to the relative issue (#1668), i hope this could be usefull.

@niccolot niccolot marked this pull request as draft February 6, 2025 13:18
@niccolot niccolot marked this pull request as ready for review February 6, 2025 13:18
@niccolot niccolot marked this pull request as draft February 6, 2025 13:18
@niccolot niccolot marked this pull request as ready for review February 10, 2025 20:14
Comment on lines +5 to +6

.vscode/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an artifact of your own personal environment, so it belongs in your personal global .gitconfig file (along with other things like editor, tool, tagging, OS and other artifacts that come from your general environment and toolsets).

Comment on lines +47 to +48
auto nonglass = make_shared<lambertian>(color(0.8, 0.2, 0.4));
world.add(make_shared<sphere>(point3(190,90,190), 90, nonglass));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a testing artifact that made it into your PR.

Comment on lines +60 to +62
cam.image_width = 400;
cam.samples_per_pixel = 1000;
cam.max_depth = 10;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More testing artifacts.

@@ -76,11 +76,14 @@ class sphere : public hittable {
if (!this->hit(ray(origin, direction), interval(0.001, infinity), rec))
return 0;

auto dist_squared = (center.at(0) - origin).length_squared();
auto cos_theta_max = std::sqrt(1 - radius*radius/dist_squared);
auto cos_theta_max = sqrt(1 - radius*radius/(center.at(0) - origin).length_squared());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the motivation for this change. It doesn't seem related to the PR purpose.

auto int_size = int(objects.size());
return objects[random_int(0, int_size-1)]->random(origin);
vec3 random(const point3& origin) const override {
int int_size = int(objects.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to make this a double declaration?

vec3 random(const point3& origin) const override {
auto int_size = int(objects.size());
return objects[random_int(0, int_size-1)]->random(origin);
vec3 random(const point3& origin) const override {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation error.

Comment on lines +64 to +67
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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern calls for a do-while loop to eliminate the code duplication.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More generally, a vector that contains a NaN value has issues before this code executes, so we still need to find the root cause for why this happens and fix it at the source. Addressing it here is too late.

auto solid_angle = 2*pi*(1-cos_theta_max);

return 1 / solid_angle;
if (std::isnan(solid_angle) || std::fabs(solid_angle) < 1e-3) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning for such a large minimum value of solid_angle? 1e-3 eliminates over half of all representable finite floating-point numbers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would solid_angle be NaN here? The only way I can is if cos_theta_max is NaN. Why would that be?

sqrt(1 - radius*radius/(center.at(0) - origin).length_squared()) must be NaN
1 - radius*radius/(center.at(0) - origin).length_squared() must be negative
radius*radius/(center.at(0) - origin).length_squared() must be greater than 1
radius*radius/(center.at(0) - origin) must be greater than 1
radius*radius must be less than center.at(0) - origin

Seems like this needs further digging to figure out why this is an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants