Skip to content

Book 3.12: Bug in final code? Black image when using lambert material for nearest object to camera in mixed density pdf approach #1265

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
hollasch opened this issue Sep 13, 2023 Discussed in #1240 · 1 comment

Comments

@hollasch
Copy link
Collaborator

Discussed in #1240

Originally posted by 1vx-437312114 August 25, 2023
This is the result of the final code of book 3 (src/TheRestOfYourLife/main.cc ):

theRestOfYourLife_400

When i change the material of the glass sphere in the cornell_box() - function into a lambert diffuse material i get a nearly black image with basically only the light source visible when i render the image:

theRestOfYourLife

This is what it should look like (rendered for comparison in the brute force path tracer without the mixed density pdf approach):

cornell_box

I tried a few things e.g. replacing the sphere with a box or changing materials of the box inside the scene to lambert diffuse. My results so far are that whenever the object which is nearest to the camera is lambert diffuse the rendering breaks and i get the nearly black image from above as the result.

I came to this after i tried implementing the mixed density pdf approach from book 3 in my own path tracer where i tried to render the original cornell box (in which everything has a diffuse material) and i got the same bad results which got me trying to test the original code.

Here are the "changes" (just one line) in the cornell_box() - function of the main.cc file inside the folder src/TheRestOfYourLife/ for changing the glas sphere in the front to a blue colored diffuse sphere:

 hittable_list cornell_box() {
    ...
    shared_ptr<material> blue = make_shared<lambertian>(color(0.0, 0.0, 0.75));   // blue lambert diffuse
    //auto glass = make_shared<dielectric>(1.5);
    objects.add(make_shared<sphere>(point3(190,90,190), 90 , blue));  // changed from 'glass' to 'blue'

    return objects;
}

Has anyone any idea what is going wrong here or what i did wrong and how to fix this? Thanks in advance.

Here is the "modified" main.cc if anyone wants to test it:

main_cc.txt

@LiuZengqiang
Copy link

I used to get a similar result (only a nearly black image with basically only the light source visible), it is caused by calling wrong function hittable->pdf_value() rather then the expected function quad->pdf_value() in runtime. I fixed it by checking and modifying function parameter types carefully (using reference or pointer). You maybe should check whether the pdf_value() is override by the subclass of hittable and the pdf whether equal near "zero".
Hope this helps.

@hollasch hollasch changed the title Book 3 - bug in final code? black image when using lambert material for nearest object to camera in mixed density pdf approach Book 3.12: Bug in final code? Black image when using lambert material for nearest object to camera in mixed density pdf approach Apr 19, 2024
@hollasch hollasch modified the milestones: v4.0.0, Backlog Jul 22, 2024
@hollasch hollasch assigned hollasch and unassigned trevordblack Jul 26, 2024
@hollasch hollasch modified the milestones: Backlog, v4.0.1 Jul 26, 2024
@hollasch hollasch removed their assignment Jul 29, 2024
@hollasch hollasch modified the milestones: v4.0.1, Backlog Aug 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants