|
1747 | 1747 | color color_from_scatter = |
1748 | 1748 | (attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf; |
1749 | 1749 |
|
1750 | | - |
1751 | 1750 | return color_from_emission + color_from_scatter; |
1752 | 1751 | } |
1753 | 1752 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
2412 | 2411 |
|
2413 | 2412 | ray scattered; |
2414 | 2413 | color attenuation; |
2415 | | - color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p); |
| 2414 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2416 | 2415 | double pdf; |
2417 | | - color albedo; |
| 2416 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 2417 | + color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p); |
2418 | 2418 |
|
2419 | | - if (!rec.mat->scatter(r, rec, albedo, scattered, pdf)) |
| 2419 | + |
| 2420 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 2421 | + if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf)) |
| 2422 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2420 | 2423 | return color_from_emission; |
2421 | 2424 |
|
2422 | 2425 |
|
|
2436 | 2439 |
|
2437 | 2440 | pdf = distance_squared / (light_cosine * light_area); |
2438 | 2441 | scattered = ray(rec.p, to_light, r.time()); |
| 2442 | + |
| 2443 | + double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered); |
2439 | 2444 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2440 | 2445 |
|
2441 | 2446 | color color_from_scatter = |
2442 | | - albedo * rec.mat->scattering_pdf(r, rec, scattered) |
2443 | | - * ray_color(scattered, depth-1) / pdf |
| 2447 | + (attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf; |
2444 | 2448 |
|
2445 | 2449 | return color_from_emission + color_from_scatter; |
2446 | 2450 | } |
|
2628 | 2632 |
|
2629 | 2633 | ray scattered; |
2630 | 2634 | color attenuation; |
2631 | | - color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
2632 | 2635 | double pdf_val; |
2633 | | - color albedo; |
| 2636 | + color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
2634 | 2637 |
|
2635 | | - if (!rec.mat->scatter(r, rec, albedo, scattered, pdf_val)) |
| 2638 | + if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_val)) |
2636 | 2639 | return color_from_emission; |
2637 | 2640 |
|
2638 | 2641 |
|
|
2642 | 2645 | pdf_val = surface_pdf.value(scattered.direction()); |
2643 | 2646 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2644 | 2647 |
|
2645 | | - color color_from_scatter = albedo |
2646 | | - * rec.mat->scattering_pdf(r, rec, scattered) |
2647 | | - * ray_color(scattered, depth-1) / pdf_val; |
| 2648 | + double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered); |
| 2649 | + |
| 2650 | + color color_from_scatter = |
| 2651 | + (attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val; |
2648 | 2652 |
|
2649 | 2653 | return color_from_emission + color_from_scatter; |
2650 | 2654 | } |
|
2806 | 2810 |
|
2807 | 2811 | ray scattered; |
2808 | 2812 | color attenuation; |
2809 | | - color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
2810 | 2813 | double pdf_val; |
2811 | | - color albedo; |
| 2814 | + color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
2812 | 2815 |
|
2813 | | - if (!rec.mat->scatter(r, rec, albedo, scattered, pdf_val)) |
| 2816 | + if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_val)) |
2814 | 2817 | return color_from_emission; |
2815 | 2818 |
|
2816 | 2819 |
|
|
2820 | 2823 | pdf_val = light_pdf.value(scattered.direction()); |
2821 | 2824 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2822 | 2825 |
|
2823 | | - color color_from_scatter = albedo |
2824 | | - * rec.mat->scattering_pdf(r, rec, scattered) |
2825 | | - * ray_color(scattered, depth-1) / pdf_val; |
| 2826 | + double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered); |
| 2827 | + |
| 2828 | + color color_from_scatter = |
| 2829 | + (attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val; |
2826 | 2830 |
|
2827 | 2831 | return color_from_emission + color_from_scatter; |
2828 | 2832 | } |
|
2941 | 2945 |
|
2942 | 2946 | ray scattered; |
2943 | 2947 | color attenuation; |
2944 | | - color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
2945 | 2948 | double pdf_val; |
2946 | | - color albedo; |
| 2949 | + color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
2947 | 2950 |
|
2948 | | - if (!rec.mat->scatter(r, rec, albedo, scattered, pdf_val)) |
| 2951 | + if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_val)) |
2949 | 2952 | return color_from_emission; |
2950 | 2953 |
|
2951 | 2954 |
|
|
2958 | 2961 | pdf_val = mixed_pdf.value(scattered.direction()); |
2959 | 2962 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2960 | 2963 |
|
2961 | | - color color_from_scatter = albedo |
2962 | | - * rec.mat->scattering_pdf(r, rec, scattered) |
2963 | | - * ray_color(scattered, depth-1) / pdf_val; |
| 2964 | + double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered); |
| 2965 | + |
| 2966 | + color color_from_scatter = |
| 2967 | + (attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val; |
2964 | 2968 |
|
2965 | 2969 | return color_from_emission + color_from_scatter; |
2966 | 2970 | } |
|
3169 | 3173 |
|
3170 | 3174 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3171 | 3175 | scatter_record srec; |
| 3176 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3172 | 3177 | color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p); |
3173 | 3178 |
|
| 3179 | + |
| 3180 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3174 | 3181 | if (!rec.mat->scatter(r, rec, srec)) |
| 3182 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3175 | 3183 | return color_from_emission; |
3176 | 3184 |
|
| 3185 | + |
| 3186 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3177 | 3187 | auto light_ptr = make_shared<hittable_pdf>(lights, rec.p); |
3178 | 3188 | mixture_pdf p(light_ptr, srec.pdf_ptr); |
3179 | 3189 |
|
3180 | 3190 | ray scattered = ray(rec.p, p.generate(), r.time()); |
3181 | 3191 | auto pdf_val = p.value(scattered.direction()); |
| 3192 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3182 | 3193 |
|
3183 | | - color color_from_scatter = (srec.attenuation |
3184 | | - * rec.mat->scattering_pdf(r, rec, scattered) |
3185 | | - * ray_color(scattered, depth-1)) / pdf_val; |
| 3194 | + double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered); |
| 3195 | + |
| 3196 | + color color_from_scatter = |
| 3197 | + (srec.attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val; |
3186 | 3198 |
|
3187 | 3199 | return color_from_emission + color_from_scatter; |
3188 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3189 | 3200 | } |
3190 | 3201 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
3191 | 3202 | [Listing [ray-color-mixture]: <kbd>[scene.h]</kbd> The ray_color function, using mixture PDF] |
|
0 commit comments