raytracing.github.io
raytracing.github.io copied to clipboard
Book 3.12: Bug in final code? Black image when using lambert material for nearest object to camera in mixed density pdf approach
Discussed in https://github.com/RayTracing/raytracing.github.io/discussions/1240
Originally posted by 1vx-437312114 August 25, 2023 This is the result of the final code of book 3 (src/TheRestOfYourLife/main.cc ):
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:
This is what it should look like (rendered for comparison in the brute force path tracer without the mixed density pdf approach):
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:
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.