|
2608 | 2608 | public:
|
2609 | 2609 | ...
|
2610 | 2610 | aabb(const interval& x, const interval& y, const interval& z)
|
2611 |
| - : x(x), y(y), z(z) |
2612 | 2611 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
| 2612 | + : x(x), y(y), z(z) |
2613 | 2613 | {
|
2614 | 2614 | pad_to_minimums();
|
2615 | 2615 | }
|
|
2624 | 2624 | y = interval(fmin(a[1],b[1]), fmax(a[1],b[1]));
|
2625 | 2625 | z = interval(fmin(a[2],b[2]), fmax(a[2],b[2]));
|
2626 | 2626 |
|
| 2627 | + |
2627 | 2628 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2628 | 2629 | pad_to_minimums();
|
2629 | 2630 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
|
2825 | 2826 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2826 | 2827 | class quad : public hittable {
|
2827 | 2828 | ...
|
| 2829 | + |
2828 | 2830 | bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
|
2829 | 2831 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2830 | 2832 | auto denom = dot(normal, r.direction());
|
|
2848 | 2850 | return true;
|
2849 | 2851 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2850 | 2852 | }
|
| 2853 | + |
2851 | 2854 | ...
|
2852 | 2855 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2853 | 2856 | [Listing [quad-plane2]: <kbd>[quad.h]</kbd> hit() method for the infinite plane]
|
|
3036 | 3039 | test method from the hit method.
|
3037 | 3040 |
|
3038 | 3041 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
3039 |
| - ... |
3040 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3041 |
| - #include <cmath> |
3042 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3043 |
| - |
3044 | 3042 | class quad : public hittable {
|
3045 | 3043 | public:
|
3046 | 3044 | ...
|
|
3060 | 3058 |
|
3061 | 3059 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
3062 | 3060 | // Determine the hit point lies within the planar shape using its plane coordinates.
|
| 3061 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3063 | 3062 | auto intersection = r.at(t);
|
| 3063 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3064 | 3064 | vec3 planar_hitpt_vector = intersection - Q;
|
3065 | 3065 | auto alpha = dot(w, cross(planar_hitpt_vector, v));
|
3066 | 3066 | auto beta = dot(w, cross(u, planar_hitpt_vector));
|
|
3093 | 3093 | return true;
|
3094 | 3094 | }
|
3095 | 3095 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
3096 |
| - ... |
| 3096 | + |
| 3097 | + private: |
| 3098 | + point3 Q; |
| 3099 | + vec3 u, v; |
| 3100 | + vec3 w; |
| 3101 | + shared_ptr<material> mat; |
| 3102 | + aabb bbox; |
| 3103 | + vec3 normal; |
| 3104 | + double D; |
3097 | 3105 | };
|
3098 | 3106 |
|
3099 | 3107 | #endif
|
|
3103 | 3111 | <div class='together'>
|
3104 | 3112 | And now we add a new scene to demonstrate our new `quad` primitive:
|
3105 | 3113 |
|
3106 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3107 |
| - ... |
| 3114 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 3115 | + #include "rtweekend.h" |
| 3116 | + |
| 3117 | + #include "bvh.h" |
| 3118 | + #include "camera.h" |
| 3119 | + #include "color.h" |
| 3120 | + #include "hittable_list.h" |
| 3121 | + #include "material.h" |
3108 | 3122 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
3109 | 3123 | #include "quad.h"
|
3110 | 3124 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
| 3125 | + #include "sphere.h" |
| 3126 | + #include "texture.h" |
| 3127 | + |
3111 | 3128 | ...
|
| 3129 | + |
| 3130 | + |
3112 | 3131 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
3113 | 3132 | void quads() {
|
3114 | 3133 | hittable_list world;
|
|
3199 | 3218 | the ray what color it is and performs no reflection. It’s very simple:
|
3200 | 3219 |
|
3201 | 3220 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
| 3221 | + class dielectric : public material { |
| 3222 | + ... |
| 3223 | + } |
| 3224 | + |
| 3225 | + |
| 3226 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3202 | 3227 | class diffuse_light : public material {
|
3203 | 3228 | public:
|
3204 | 3229 | diffuse_light(shared_ptr<texture> tex) : tex(tex) {}
|
|
3305 | 3330 | cam.aspect_ratio = 16.0 / 9.0;
|
3306 | 3331 | cam.image_width = 400;
|
3307 | 3332 | cam.samples_per_pixel = 100;
|
3308 |
| - cam.max_depth = 50; |
| 3333 | + cam.max_depth = 20; |
3309 | 3334 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
3310 | 3335 | cam.background = color(0.70, 0.80, 1.00);
|
3311 | 3336 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
|
3522 | 3547 | 
|
3524 | 3549 |
|
3525 |
| -This image is very noisy because the light is small. |
| 3550 | +This image is very noisy because the light is small, so most random rays don't hit the light source. |
3526 | 3551 |
|
3527 | 3552 | </div>
|
3528 | 3553 |
|
|
3534 | 3559 | create a function that returns a box, by creating a `hittable_list` of six rectangles:
|
3535 | 3560 |
|
3536 | 3561 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
3537 |
| - ... |
| 3562 | + #include "rtweekend.h" |
| 3563 | + |
| 3564 | + #include "hittable.h" |
| 3565 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3538 | 3566 | #include "hittable_list.h"
|
3539 |
| - ... |
| 3567 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 3568 | + |
| 3569 | + class quad : public hittable { |
| 3570 | + }; |
| 3571 | + |
| 3572 | + |
| 3573 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3540 | 3574 | inline shared_ptr<hittable_list> box(const point3& a, const point3& b, shared_ptr<material> mat)
|
3541 | 3575 | {
|
3542 | 3576 | // Returns the 3D box (six sides) that contains the two opposite vertices a & b.
|
|
3623 | 3657 | make this happen.
|
3624 | 3658 |
|
3625 | 3659 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
| 3660 | + class hittable { |
| 3661 | + ... |
| 3662 | + }; |
| 3663 | + |
| 3664 | + |
| 3665 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3626 | 3666 | class translate : public hittable {
|
3627 | 3667 | public:
|
3628 | 3668 | bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
|
|
3661 | 3701 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
3662 | 3702 |
|
3663 | 3703 | bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
|
3664 |
| - // Move the ray backwards by the offset |
3665 |
| - ray offset_r(r.origin() - offset, r.direction(), r.time()); |
3666 |
| - |
3667 |
| - // Determine where (if any) an intersection occurs along the offset ray |
3668 |
| - if (!object->hit(offset_r, ray_t, rec)) |
3669 |
| - return false; |
3670 |
| - |
3671 |
| - // Move the intersection point forwards by the offset |
3672 |
| - rec.p += offset; |
3673 |
| - |
3674 |
| - return true; |
| 3704 | + ... |
3675 | 3705 | }
|
3676 | 3706 |
|
3677 | 3707 |
|
|
3807 | 3837 | We can now create a class for y-rotation. Let's tackle the hit function first:
|
3808 | 3838 |
|
3809 | 3839 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
| 3840 | + class translate : public hittable { |
| 3841 | + ... |
| 3842 | + }; |
| 3843 | + |
| 3844 | + |
| 3845 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3810 | 3846 | class rotate_y : public hittable {
|
3811 | 3847 | public:
|
3812 | 3848 |
|
|
4065 | 4101 | The scattering function of isotropic picks a uniform random direction:
|
4066 | 4102 |
|
4067 | 4103 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
| 4104 | + class diffuse_light : public material { |
| 4105 | + ... |
| 4106 | + }; |
| 4107 | + |
| 4108 | + |
| 4109 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
4068 | 4110 | class isotropic : public material {
|
4069 | 4111 | public:
|
4070 | 4112 | isotropic(const color& c) : tex(make_shared<solid_color>(c)) {}
|
|
4101 | 4143 | If we replace the two blocks with smoke and fog (dark and light particles), and make the light
|
4102 | 4144 | bigger (and dimmer so it doesn’t blow out the scene) for faster convergence:
|
4103 | 4145 |
|
| 4146 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 4147 | + #include "rtweekend.h" |
| 4148 | + |
| 4149 | + #include "bvh.h" |
| 4150 | + #include "camera.h" |
| 4151 | + #include "color.h" |
4104 | 4152 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
4105 | 4153 | #include "constant_medium.h"
|
4106 | 4154 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
| 4155 | + #include "hittable_list.h" |
| 4156 | + #include "material.h" |
| 4157 | + #include "quad.h" |
| 4158 | + #include "sphere.h" |
| 4159 | + #include "texture.h" |
| 4160 | + |
4107 | 4161 | ...
|
| 4162 | + |
| 4163 | + |
4108 | 4164 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
4109 | 4165 | void cornell_smoke() {
|
4110 | 4166 | hittable_list world;
|
|
4190 | 4246 | Also note that we'll parameterize this final scene to support a lower quality render for quick
|
4191 | 4247 | testing.
|
4192 | 4248 |
|
4193 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
4194 |
| - ... |
4195 |
| - |
4196 | 4249 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
4197 | 4250 | void final_scene(int image_width, int samples_per_pixel, int max_depth) {
|
4198 | 4251 | hittable_list boxes1;
|
|
4276 | 4329 |
|
4277 | 4330 | int main() {
|
4278 | 4331 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
4279 |
| - switch (0) { |
| 4332 | + switch (9) { |
4280 | 4333 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
4281 | 4334 | case 1: bouncing_spheres(); break;
|
4282 | 4335 | case 2: checkered_spheres(); break;
|
|
0 commit comments