|
1818 | 1818 | see. |
1819 | 1819 |
|
1820 | 1820 |  |
| 1821 | + ](../images/img-3.04-cornell-imperfect.jpg class='pixel') |
1822 | 1822 |
|
1823 | 1823 | Make sure to return the PDF to the scattering PDF. |
1824 | 1824 |
|
|
1870 | 1870 | return true; |
1871 | 1871 | } |
1872 | 1872 |
|
1873 | | - |
1874 | 1873 | double scattering_pdf(const ray& r_in, const hit_record& rec, const ray& scattered) |
1875 | 1874 | const override { |
1876 | 1875 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
|
1887 | 1886 | our uniform hemispherical diffuse. When rendering, we should get a slightly different image. |
1888 | 1887 |
|
1889 | 1888 |  |
| 1889 | + ](../images/img-3.05-cornell-uniform-hemi.jpg class='pixel') |
1891 | 1890 |
|
1892 | 1891 | It’s pretty close to our old picture, but there are differences that are not just noise. The front |
1893 | 1892 | of the tall box is much more uniform in color. If you aren't sure what the best sampling pattern for |
|
2399 | 2398 | ray scattered; |
2400 | 2399 | color attenuation; |
2401 | 2400 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2402 | | - double pdf_value; // TODO: What are we supposed to do with the returned PDF? |
| 2401 | + double pdf_value; |
2403 | 2402 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2404 | 2403 | color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p); |
2405 | 2404 |
|
|
2409 | 2408 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2410 | 2409 | return color_from_emission; |
2411 | 2410 |
|
| 2411 | + double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered); |
| 2412 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 2413 | + pdf_value = scattering_pdf; |
| 2414 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 2415 | + |
2412 | 2416 | ... |
2413 | 2417 | } |
2414 | 2418 |
|
|
2536 | 2540 |
|
2537 | 2541 | ray scattered; |
2538 | 2542 | color attenuation; |
2539 | | - double pdf_value; // TODO: What are we supposed to do with the returned PDF? |
| 2543 | + double pdf_value; |
2540 | 2544 | color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p); |
2541 | 2545 |
|
2542 | 2546 | if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_value)) |
|
2798 | 2802 |
|
2799 | 2803 | ray scattered; |
2800 | 2804 | color attenuation; |
2801 | | - double pdf_value; // TODO: What are we supposed to do with the returned PDF? |
| 2805 | + double pdf_value; |
2802 | 2806 | color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
2803 | 2807 |
|
2804 | 2808 | if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_value)) |
|
2869 | 2873 |
|
2870 | 2874 | ... |
2871 | 2875 |
|
| 2876 | + |
| 2877 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2872 | 2878 | class hittable_pdf : public pdf { |
2873 | 2879 | public: |
2874 | 2880 | hittable_pdf(const hittable& objects, const point3& origin) |
|
3034 | 3040 |
|
3035 | 3041 | ray scattered; |
3036 | 3042 | color attenuation; |
3037 | | - double pdf_value; // TODO: What are we supposed to do with the returned PDF? |
| 3043 | + double pdf_value; |
3038 | 3044 | color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
3039 | 3045 |
|
3040 | 3046 | if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_value)) |
3041 | 3047 | return color_from_emission; |
3042 | 3048 |
|
3043 | 3049 |
|
3044 | 3050 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3045 | | - hittable_pdf light_pdf(light_ptr, rec.p); |
| 3051 | + hittable_pdf light_pdf(lights, rec.p); |
3046 | 3052 | scattered = ray(rec.p, light_pdf.generate(), r.time()); |
3047 | 3053 | pdf_value = light_pdf.value(scattered.direction()); |
3048 | 3054 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
3084 | 3090 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3085 | 3091 |
|
3086 | 3092 | camera cam; |
| 3093 | + |
| 3094 | + cam.aspect_ratio = 1.0; |
| 3095 | + cam.image_width = 600; |
| 3096 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 3097 | + cam.samples_per_pixel = 10; |
| 3098 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 3099 | + cam.max_depth = 50; |
| 3100 | + cam.background = color(0,0,0); |
| 3101 | + |
3087 | 3102 | ... |
3088 | 3103 |
|
3089 | 3104 |
|
|
3203 | 3218 |
|
3204 | 3219 |
|
3205 | 3220 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3206 | | - auto p0 = make_shared<hittable_pdf>(light_ptr, rec.p); |
| 3221 | + auto p0 = make_shared<hittable_pdf>(lights, rec.p); |
3207 | 3222 | auto p1 = make_shared<cosine_pdf>(rec.normal); |
3208 | 3223 | mixture_pdf mixed_pdf(p0, p1); |
3209 | 3224 |
|
|
3224 | 3239 | </div> |
3225 | 3240 |
|
3226 | 3241 | <div class='together'> |
3227 | | -1000 samples per pixel yields: |
| 3242 | +Updating `main.cc` to 1000 samples per pixel (not listed) yields: |
3228 | 3243 |
|
3229 | 3244 |  |
|
3311 | 3326 | <div class='together'> |
3312 | 3327 | We can redesign `material` and stuff all the new arguments into a class like we did for `hittable`: |
3313 | 3328 |
|
| 3329 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 3330 | + #include "rtweekend.h" |
| 3331 | + |
| 3332 | + #include "onb.h" |
| 3333 | + #include "texture.h" |
| 3334 | + |
| 3335 | + class hit_record; |
| 3336 | + |
| 3337 | + |
3314 | 3338 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3315 | 3339 | class scatter_record { |
3316 | 3340 | public: |
|
3513 | 3537 | double fuzz; |
3514 | 3538 | }; |
3515 | 3539 |
|
3516 | | - ... |
3517 | | - |
3518 | 3540 | class dielectric : public material { |
3519 | 3541 | public: |
3520 | 3542 | dielectric(double refraction_index) : refraction_index(refraction_index) {} |
|
3717 | 3739 | public: |
3718 | 3740 | ... |
3719 | 3741 |
|
| 3742 | + aabb bounding_box() const override { return bbox; } |
| 3743 | + |
3720 | 3744 |
|
3721 | 3745 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3722 | 3746 | double pdf_value(const point3& origin, const vec3& direction) const override { |
|
3818 | 3842 | public: |
3819 | 3843 | ... |
3820 | 3844 |
|
| 3845 | + aabb bounding_box() const override { return bbox; } |
| 3846 | + |
3821 | 3847 |
|
3822 | 3848 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3823 | 3849 | double pdf_value(const point3& origin, const vec3& direction) const override { |
|
3854 | 3880 | hittable_list lights; |
3855 | 3881 | lights.add( |
3856 | 3882 | make_shared<quad>(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), empty_material)); |
3857 | | - lights.add(make_shared<sphere>(point3(190, 90, 190), 90, m)); |
| 3883 | + lights.add(make_shared<sphere>(point3(190, 90, 190), 90, empty_material)); |
3858 | 3884 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3859 | 3885 |
|
3860 | 3886 | ... |
|
0 commit comments