|
2202 | 2202 | <div class='together'> |
2203 | 2203 | We get: |
2204 | 2204 |
|
2205 | | -  |
2206 | | - |
2207 | | -</div> |
2208 | | - |
2209 | | - |
2210 | | -Flipped Objects |
2211 | | ----------------- |
2212 | | -<div class='together'> |
2213 | | -This is very noisy because the light is small. But we have a problem: some of the walls are facing |
2214 | | -the wrong way. We haven't specified that a diffuse material should behave differently on different |
2215 | | -faces of the object, but what if the Cornell box had a different pattern on the inside and outside |
2216 | | -walls? The rectangle objects are described such that their front faces are always in the directions |
2217 | | -$(1,0,0)$, $(0,1,0)$, or $(0,0,1)$. We need a way to switch the faces of an object. Let’s make a |
2218 | | -hittable that does nothing but hold another hittable, and flips the face: |
2219 | | - |
2220 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2221 | | - class flip_face : public hittable { |
2222 | | - public: |
2223 | | - flip_face(shared_ptr<hittable> p) : ptr(p) {} |
2224 | | - |
2225 | | - virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const { |
2226 | | - if (!ptr->hit(r, t_min, t_max, rec)) |
2227 | | - return false; |
2228 | | - |
2229 | | - rec.front_face = !rec.front_face; |
2230 | | - return true; |
2231 | | - } |
2232 | | - |
2233 | | - virtual bool bounding_box(double t0, double t1, aabb& output_box) const { |
2234 | | - return ptr->bounding_box(t0, t1, output_box); |
2235 | | - } |
2236 | | - |
2237 | | - public: |
2238 | | - shared_ptr<hittable> ptr; |
2239 | | - }; |
2240 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2241 | | - [Listing [flip-face]: <kbd>[hittable.h]</kbd> Flip-Face function] |
2242 | | -</div> |
2243 | | - |
2244 | | -<div class='together'> |
2245 | | -This makes Cornell: |
2246 | | - |
2247 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2248 | | - hittable_list cornell_box() { |
2249 | | - hittable_list objects; |
2250 | | - |
2251 | | - auto red = make_shared<lambertian>(make_shared<solid_color>(.65, .05, .05)); |
2252 | | - auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
2253 | | - auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
2254 | | - auto light = make_shared<diffuse_light>(make_shared<solid_color>(15, 15, 15)); |
2255 | | - |
2256 | | - |
2257 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2258 | | - objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green))); |
2259 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2260 | | - objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red)); |
2261 | | - objects.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light)); |
2262 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2263 | | - objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white))); |
2264 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2265 | | - objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white)); |
2266 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2267 | | - objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white))); |
2268 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2269 | | - |
2270 | | - return objects; |
2271 | | - } |
2272 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2273 | | - [Listing [cornell-box-flipped]: <kbd>[main.cc]</kbd> Empty Cornell box with flipped rectangles] |
2274 | | -</div> |
2275 | | - |
2276 | | -<div class='together'> |
2277 | | -And voila: |
2278 | | - |
2279 | | -  |
| 2205 | +  |
2280 | 2206 |
|
| 2207 | +This image is very noisy because the light is small. |
2281 | 2208 | </div> |
2282 | 2209 |
|
2283 | 2210 |
|
|
2312 | 2239 | box_max = p1; |
2313 | 2240 |
|
2314 | 2241 | sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr)); |
2315 | | - sides.add(make_shared<flip_face>( |
2316 | | - make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr))); |
| 2242 | + sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)); |
2317 | 2243 |
|
2318 | 2244 | sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr)); |
2319 | | - sides.add(make_shared<flip_face>( |
2320 | | - make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr))); |
| 2245 | + sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)); |
2321 | 2246 |
|
2322 | 2247 | sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr)); |
2323 | | - sides.add(make_shared<flip_face>( |
2324 | | - make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr))); |
| 2248 | + sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)); |
2325 | 2249 | } |
2326 | 2250 |
|
2327 | 2251 | bool box::hit(const ray& r, double t0, double t1, hit_record& rec) const { |
|
2344 | 2268 | <div class='together'> |
2345 | 2269 | This gives: |
2346 | 2270 |
|
2347 | | -  |
| 2271 | +  |
2348 | 2272 |
|
2349 | 2273 | </div> |
2350 | 2274 |
|
|
2572 | 2496 | <div class='together'> |
2573 | 2497 | Which yields: |
2574 | 2498 |
|
2575 | | -  |
| 2499 | +  |
2576 | 2500 |
|
2577 | 2501 | </div> |
2578 | 2502 |
|
|
2739 | 2663 | auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
2740 | 2664 | auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7)); |
2741 | 2665 |
|
2742 | | - objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green))); |
| 2666 | + objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green)); |
2743 | 2667 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red)); |
2744 | 2668 | objects.add(make_shared<xz_rect>(113, 443, 127, 432, 554, light)); |
2745 | | - objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white))); |
| 2669 | + objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white)); |
2746 | 2670 | objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white)); |
2747 | | - objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white))); |
| 2671 | + objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white)); |
2748 | 2672 |
|
2749 | 2673 | shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white); |
2750 | 2674 | box1 = make_shared<rotate_y>(box1, 15); |
|
2766 | 2690 | <div class='together'> |
2767 | 2691 | We get: |
2768 | 2692 |
|
2769 | | -  |
| 2693 | +  |
2770 | 2694 |
|
2771 | 2695 | </div> |
2772 | 2696 |
|
|
2854 | 2778 | <div class='together'> |
2855 | 2779 | Running it with 10,000 rays per pixel yields: |
2856 | 2780 |
|
2857 | | -  |
| 2781 | +  |
2858 | 2782 |
|
2859 | 2783 | </div> |
2860 | 2784 |
|
|
0 commit comments