|
2185 | 2185 | <div class='together'>
|
2186 | 2186 | We get:
|
2187 | 2187 |
|
2188 |
| -  |
2189 |
| - |
2190 |
| -</div> |
2191 |
| - |
2192 |
| - |
2193 |
| -Flipped Objects |
2194 |
| ----------------- |
2195 |
| -<div class='together'> |
2196 |
| -This is very noisy because the light is small. But we have a problem: some of the walls are facing |
2197 |
| -the wrong way. We haven't specified that a diffuse material should behave differently on different |
2198 |
| -faces of the object, but what if the Cornell box had a different pattern on the inside and outside |
2199 |
| -walls? The rectangle objects are described such that their front faces are always in the directions |
2200 |
| -$(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 |
2201 |
| -hittable that does nothing but hold another hittable, and flips the face: |
2202 |
| - |
2203 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2204 |
| - class flip_face : public hittable { |
2205 |
| - public: |
2206 |
| - flip_face(shared_ptr<hittable> p) : ptr(p) {} |
2207 |
| - |
2208 |
| - virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const { |
2209 |
| - if (!ptr->hit(r, t_min, t_max, rec)) |
2210 |
| - return false; |
2211 |
| - |
2212 |
| - rec.front_face = !rec.front_face; |
2213 |
| - return true; |
2214 |
| - } |
2215 |
| - |
2216 |
| - virtual bool bounding_box(double t0, double t1, aabb& output_box) const { |
2217 |
| - return ptr->bounding_box(t0, t1, output_box); |
2218 |
| - } |
2219 |
| - |
2220 |
| - public: |
2221 |
| - shared_ptr<hittable> ptr; |
2222 |
| - }; |
2223 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2224 |
| - [Listing [flip-face]: <kbd>[hittable.h]</kbd> Flip-Face function] |
2225 |
| -</div> |
2226 |
| - |
2227 |
| -<div class='together'> |
2228 |
| -This makes Cornell: |
2229 |
| - |
2230 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2231 |
| - hittable_list cornell_box() { |
2232 |
| - hittable_list objects; |
2233 |
| - |
2234 |
| - auto red = make_shared<lambertian>(color(.65, .05, .05)); |
2235 |
| - auto white = make_shared<lambertian>(color(.73, .73, .73)); |
2236 |
| - auto green = make_shared<lambertian>(color(.12, .45, .15)); |
2237 |
| - auto light = make_shared<diffuse_light>(color(15, 15, 15)); |
2238 |
| - |
2239 |
| - |
2240 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2241 |
| - objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green))); |
2242 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2243 |
| - objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red)); |
2244 |
| - objects.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light)); |
2245 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2246 |
| - objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white))); |
2247 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2248 |
| - objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white)); |
2249 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
2250 |
| - objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white))); |
2251 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2252 |
| - |
2253 |
| - return objects; |
2254 |
| - } |
2255 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2256 |
| - [Listing [cornell-box-flipped]: <kbd>[main.cc]</kbd> Empty Cornell box with flipped rectangles] |
2257 |
| -</div> |
2258 |
| - |
2259 |
| -<div class='together'> |
2260 |
| -And voila: |
2261 |
| - |
2262 |
| -  |
| 2188 | +  |
2263 | 2189 |
|
| 2190 | +This image is very noisy because the light is small. |
2264 | 2191 | </div>
|
2265 | 2192 |
|
2266 | 2193 |
|
|
2295 | 2222 | box_max = p1;
|
2296 | 2223 |
|
2297 | 2224 | sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr));
|
2298 |
| - sides.add(make_shared<flip_face>( |
2299 |
| - make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr))); |
| 2225 | + sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)); |
2300 | 2226 |
|
2301 | 2227 | sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr));
|
2302 |
| - sides.add(make_shared<flip_face>( |
2303 |
| - make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr))); |
| 2228 | + sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)); |
2304 | 2229 |
|
2305 | 2230 | sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr));
|
2306 |
| - sides.add(make_shared<flip_face>( |
2307 |
| - make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr))); |
| 2231 | + sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)); |
2308 | 2232 | }
|
2309 | 2233 |
|
2310 | 2234 | bool box::hit(const ray& r, double t0, double t1, hit_record& rec) const {
|
|
2327 | 2251 | <div class='together'>
|
2328 | 2252 | This gives:
|
2329 | 2253 |
|
2330 |
| -  |
| 2254 | +  |
2331 | 2255 |
|
2332 | 2256 | </div>
|
2333 | 2257 |
|
|
2555 | 2479 | <div class='together'>
|
2556 | 2480 | Which yields:
|
2557 | 2481 |
|
2558 |
| -  |
| 2482 | +  |
2559 | 2483 |
|
2560 | 2484 | </div>
|
2561 | 2485 |
|
|
2728 | 2652 | auto green = make_shared<lambertian>(color(.12, .45, .15));
|
2729 | 2653 | auto light = make_shared<diffuse_light>(color(7, 7, 7));
|
2730 | 2654 |
|
2731 |
| - objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green))); |
| 2655 | + objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green)); |
2732 | 2656 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
|
2733 | 2657 | objects.add(make_shared<xz_rect>(113, 443, 127, 432, 554, light));
|
2734 |
| - objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white))); |
| 2658 | + objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white)); |
2735 | 2659 | objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
|
2736 |
| - objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white))); |
| 2660 | + objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white)); |
2737 | 2661 |
|
2738 | 2662 | shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
|
2739 | 2663 | box1 = make_shared<rotate_y>(box1, 15);
|
|
2755 | 2679 | <div class='together'>
|
2756 | 2680 | We get:
|
2757 | 2681 |
|
2758 |
| -  |
| 2682 | +  |
2759 | 2683 |
|
2760 | 2684 | </div>
|
2761 | 2685 |
|
|
2839 | 2763 | <div class='together'>
|
2840 | 2764 | Running it with 10,000 rays per pixel yields:
|
2841 | 2765 |
|
2842 |
| -  |
| 2766 | +  |
2843 | 2767 |
|
2844 | 2768 | </div>
|
2845 | 2769 |
|
|
0 commit comments