|
751 | 751 |
|
752 | 752 | Returning to the Cornell Box
|
753 | 753 | -----------------------------
|
754 |
| -<div class='together'> |
755 | 754 | Let’s do a simple refactoring and temporarily remove all materials that aren’t Lambertian. We can
|
756 | 755 | use our Cornell Box scene again, and let’s generate the camera in the function that generates the
|
757 |
| -model: |
| 756 | +model. |
758 | 757 |
|
759 | 758 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
760 |
| - hittable_list cornell_box(camera& cam, double aspect) { |
| 759 | + ... |
| 760 | + color ray_color( |
| 761 | + ... |
| 762 | + |
| 763 | + hittable_list cornell_box() { |
761 | 764 | hittable_list world;
|
762 | 765 |
|
763 | 766 | auto red = make_shared<lambertian>(color(.65, .05, .05));
|
|
782 | 785 | box2 = make_shared<translate>(box2, vec3(130,0,65));
|
783 | 786 | world.add(box2);
|
784 | 787 |
|
| 788 | + return world; |
| 789 | + } |
| 790 | + |
| 791 | + int main() { |
| 792 | + // Image |
| 793 | + |
| 794 | + const auto aspect_ratio = 1.0 / 1.0; |
| 795 | + const int image_width = 600; |
| 796 | + const int image_height = static_cast<int>(image_width / aspect_ratio); |
| 797 | + const int samples_per_pixel = 100; |
| 798 | + const int max_depth = 50; |
| 799 | + |
| 800 | + // World |
| 801 | + |
| 802 | + auto lights = make_shared<hittable_list>(); |
| 803 | + lights->add(make_shared<xz_rect>(213, 343, 227, 332, 554, shared_ptr<material>())); |
| 804 | + lights->add(make_shared<sphere>(point3(190, 90, 190), 90, shared_ptr<material>())); |
| 805 | + |
| 806 | + auto world = cornell_box(); |
| 807 | + |
| 808 | + color background(0,0,0); |
| 809 | + |
| 810 | + // Camera |
| 811 | + |
785 | 812 | point3 lookfrom(278, 278, -800);
|
786 | 813 | point3 lookat(278, 278, 0);
|
787 |
| - vec3 vup(0, 1, 0); |
| 814 | + vec3 up(0, 1, 0); |
788 | 815 | auto dist_to_focus = 10.0;
|
789 | 816 | auto aperture = 0.0;
|
790 | 817 | auto vfov = 40.0;
|
791 | 818 | auto t0 = 0.0;
|
792 | 819 | auto t1 = 1.0;
|
793 | 820 |
|
794 |
| - cam = camera(lookfrom, lookat, vup, vfov, aspect, aperture, dist_to_focus, t0, t1); |
| 821 | + camera cam(lookfrom, lookat, up, vfov, aspect_ratio, aperture, dist_to_focus, t0, t1); |
795 | 822 |
|
796 |
| - return world; |
| 823 | + // Render |
| 824 | + |
| 825 | + std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n"; |
| 826 | + |
| 827 | + for (int j = image_height-1; j >= 0; --j) { |
| 828 | + ... |
797 | 829 | }
|
798 | 830 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
799 | 831 | [Listing [cornell-box]: <kbd>[main.cc]</kbd> Cornell box, refactored]
|
800 |
| -</div> |
801 | 832 |
|
802 | 833 | <div class='together'>
|
803 | 834 | At 500×500 my code produces this image in 10min on 1 core of my Macbook:
|
|
0 commit comments