|
1041 | 1041 | class lambertian : public material { |
1042 | 1042 | public: |
1043 | 1043 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 1044 | + lambertian(const color& a) : albedo(make_shared<solid_color>(a)) {} |
1044 | 1045 | lambertian(shared_ptr<texture> a) : albedo(a) {} |
1045 | 1046 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1046 | 1047 |
|
|
1064 | 1065 | [Listing [lambertian-textured]: <kbd>[material.h]</kbd> Lambertian material with texture] |
1065 | 1066 | </div> |
1066 | 1067 |
|
1067 | | -<div class='together'> |
1068 | | -Where you used to have code like this: |
1069 | | - |
1070 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1071 | | - ...make_shared<lambertian>(color(0.5, 0.5, 0.5)) |
1072 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1073 | | - [Listing [lam-solid]: <kbd>[main.cc]</kbd> Lambertian material with solid color] |
1074 | | - |
1075 | | -now you should replace the `color(...)` with `make_shared<solid_color>(...)` |
1076 | | - |
1077 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1078 | | - ...make_shared<lambertian>(make_shared<solid_color>(0.5, 0.5, 0.5)) |
1079 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1080 | | - [Listing [lam-textured]: <kbd>[main.cc]</kbd> Lambertian material with texture] |
1081 | | - |
1082 | | -Update all three occurrences of lambertian in the `random_scene()` function in `main.cc`. |
1083 | | -</div> |
1084 | | - |
1085 | 1068 |
|
1086 | 1069 | A Checker Texture |
1087 | 1070 | ------------------ |
|
1094 | 1077 | class checker_texture : public texture { |
1095 | 1078 | public: |
1096 | 1079 | checker_texture() {} |
1097 | | - checker_texture(shared_ptr<texture> t0, shared_ptr<texture> t1): even(t0), odd(t1) {} |
| 1080 | + |
| 1081 | + checker_texture(shared_ptr<texture> t0, shared_ptr<texture> t1) |
| 1082 | + : even(t0), odd(t1) {} |
| 1083 | + |
| 1084 | + checker_texture(color c1, color c2) |
| 1085 | + : even(make_shared<solid_color>(c1)) , odd(make_shared<solid_color>(c2)) {} |
1098 | 1086 |
|
1099 | 1087 | virtual color value(double u, double v, const point3& p) const { |
1100 | 1088 | auto sines = sin(10*p.x())*sin(10*p.y())*sin(10*p.z()); |
|
1119 | 1107 | If we add this to our `random_scene()` function’s base sphere: |
1120 | 1108 |
|
1121 | 1109 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1122 | | - auto checker = make_shared<checker_texture>( |
1123 | | - make_shared<solid_color>(0.2, 0.3, 0.1), |
1124 | | - make_shared<solid_color>(0.9, 0.9, 0.9) |
1125 | | - ); |
| 1110 | + auto checker = make_shared<checker_texture>(color(0.2, 0.3, 0.1), color(0.9, 0.9, 0.9)); |
1126 | 1111 |
|
1127 | 1112 | world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker))); |
1128 | 1113 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
1144 | 1129 | hittable_list two_spheres() { |
1145 | 1130 | hittable_list objects; |
1146 | 1131 |
|
1147 | | - auto checker = make_shared<checker_texture>( |
1148 | | - make_shared<solid_color>(0.2, 0.3, 0.1), |
1149 | | - make_shared<solid_color>(0.9, 0.9, 0.9) |
1150 | | - ); |
| 1132 | + auto checker = make_shared<checker_texture>(color(0.2, 0.3, 0.1), color(0.9, 0.9, 0.9)); |
1151 | 1133 |
|
1152 | 1134 | objects.add(make_shared<sphere>(point3(0,-10, 0), 10, make_shared<lambertian>(checker))); |
1153 | 1135 | objects.add(make_shared<sphere>(point3(0, 10, 0), 10, make_shared<lambertian>(checker))); |
|
1843 | 1825 | class diffuse_light : public material { |
1844 | 1826 | public: |
1845 | 1827 | diffuse_light(shared_ptr<texture> a) : emit(a) {} |
| 1828 | + diffuse_light(color c) : emit(make_shared<solid_color>(c)) {} |
1846 | 1829 |
|
1847 | 1830 | virtual bool scatter( |
1848 | 1831 | const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
|
2028 | 2011 | objects.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(pertext))); |
2029 | 2012 | objects.add(make_shared<sphere>(point3(0,2,0), 2, make_shared<lambertian>(pertext))); |
2030 | 2013 |
|
2031 | | - auto difflight = make_shared<diffuse_light>(make_shared<solid_color>(4,4,4)); |
| 2014 | + auto difflight = make_shared<diffuse_light>(color(4,4,4)); |
2032 | 2015 | objects.add(make_shared<sphere>(point3(0,7,0), 2, difflight)); |
2033 | 2016 | objects.add(make_shared<xy_rect>(3, 5, 1, 3, -2, difflight)); |
2034 | 2017 |
|
|
2163 | 2146 | hittable_list cornell_box() { |
2164 | 2147 | hittable_list objects; |
2165 | 2148 |
|
2166 | | - auto red = make_shared<lambertian>(make_shared<solid_color>(.65, .05, .05)); |
2167 | | - auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
2168 | | - auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
2169 | | - auto light = make_shared<diffuse_light>(make_shared<solid_color>(15, 15, 15)); |
| 2149 | + auto red = make_shared<lambertian>(color(.65, .05, .05)); |
| 2150 | + auto white = make_shared<lambertian>(color(.73, .73, .73)); |
| 2151 | + auto green = make_shared<lambertian>(color(.12, .45, .15)); |
| 2152 | + auto light = make_shared<diffuse_light>(color(15, 15, 15)); |
2170 | 2153 |
|
2171 | 2154 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green)); |
2172 | 2155 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red)); |
|
2248 | 2231 | hittable_list cornell_box() { |
2249 | 2232 | hittable_list objects; |
2250 | 2233 |
|
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)); |
| 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)); |
2255 | 2238 |
|
2256 | 2239 |
|
2257 | 2240 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
|
2616 | 2599 | class constant_medium : public hittable { |
2617 | 2600 | public: |
2618 | 2601 | constant_medium(shared_ptr<hittable> b, double d, shared_ptr<texture> a) |
2619 | | - : boundary(b), neg_inv_density(-1/d) |
2620 | | - { |
2621 | | - phase_function = make_shared<isotropic>(a); |
2622 | | - } |
| 2602 | + : boundary(b), |
| 2603 | + neg_inv_density(-1/d), |
| 2604 | + phase_function(make_shared<isotropic>(a)) |
| 2605 | + {} |
| 2606 | + |
| 2607 | + constant_medium(shared_ptr<hittable> b, double d, color c) |
| 2608 | + : boundary(b), |
| 2609 | + neg_inv_density(-1/d), |
| 2610 | + phase_function(make_shared<isotropic>(color(c))) |
| 2611 | + {} |
2623 | 2612 |
|
2624 | 2613 | virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const; |
2625 | 2614 |
|
|
2734 | 2723 | hittable_list cornell_smoke() { |
2735 | 2724 | hittable_list objects; |
2736 | 2725 |
|
2737 | | - auto red = make_shared<lambertian>(make_shared<solid_color>(.65, .05, .05)); |
2738 | | - auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
2739 | | - auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
2740 | | - auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7)); |
| 2726 | + auto red = make_shared<lambertian>(color(.65, .05, .05)); |
| 2727 | + auto white = make_shared<lambertian>(color(.73, .73, .73)); |
| 2728 | + auto green = make_shared<lambertian>(color(.12, .45, .15)); |
| 2729 | + auto light = make_shared<diffuse_light>(color(7, 7, 7)); |
2741 | 2730 |
|
2742 | 2731 | objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green))); |
2743 | 2732 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red)); |
|
2754 | 2743 | box2 = make_shared<rotate_y>(box2, -18); |
2755 | 2744 | box2 = make_shared<translate>(box2, vec3(130,0,65)); |
2756 | 2745 |
|
2757 | | - objects.add(make_shared<constant_medium>(box1, 0.01, make_shared<solid_color>(0,0,0))); |
2758 | | - objects.add(make_shared<constant_medium>(box2, 0.01, make_shared<solid_color>(1,1,1))); |
| 2746 | + objects.add(make_shared<constant_medium>(box1, 0.01, color(0,0,0))); |
| 2747 | + objects.add(make_shared<constant_medium>(box2, 0.01, color(1,1,1))); |
2759 | 2748 |
|
2760 | 2749 | return objects; |
2761 | 2750 | } |
|
2783 | 2772 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2784 | 2773 | hittable_list final_scene() { |
2785 | 2774 | hittable_list boxes1; |
2786 | | - auto ground = make_shared<lambertian>(make_shared<solid_color>(0.48, 0.83, 0.53)); |
| 2775 | + auto ground = make_shared<lambertian>(color(0.48, 0.83, 0.53)); |
2787 | 2776 |
|
2788 | 2777 | const int boxes_per_side = 20; |
2789 | 2778 | for (int i = 0; i < boxes_per_side; i++) { |
|
2804 | 2793 |
|
2805 | 2794 | objects.add(make_shared<bvh_node>(boxes1, 0, 1)); |
2806 | 2795 |
|
2807 | | - auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7)); |
| 2796 | + auto light = make_shared<diffuse_light>(color(7, 7, 7)); |
2808 | 2797 | objects.add(make_shared<xz_rect>(123, 423, 147, 412, 554, light)); |
2809 | 2798 |
|
2810 | 2799 | auto center1 = point3(400, 400, 200); |
2811 | 2800 | auto center2 = center1 + vec3(30,0,0); |
2812 | | - auto moving_sphere_material = |
2813 | | - make_shared<lambertian>(make_shared<solid_color>(0.7, 0.3, 0.1)); |
| 2801 | + auto moving_sphere_material = make_shared<lambertian>(color(0.7, 0.3, 0.1)); |
2814 | 2802 | objects.add(make_shared<moving_sphere>(center1, center2, 0, 1, 50, moving_sphere_material)); |
2815 | 2803 |
|
2816 | 2804 | objects.add(make_shared<sphere>(point3(260, 150, 45), 50, make_shared<dielectric>(1.5))); |
|
2820 | 2808 |
|
2821 | 2809 | auto boundary = make_shared<sphere>(point3(360,150,145), 70, make_shared<dielectric>(1.5)); |
2822 | 2810 | objects.add(boundary); |
2823 | | - objects.add(make_shared<constant_medium>( |
2824 | | - boundary, 0.2, make_shared<solid_color>(0.2, 0.4, 0.9) |
2825 | | - )); |
| 2811 | + objects.add(make_shared<constant_medium>(boundary, 0.2, color(0.2, 0.4, 0.9))); |
2826 | 2812 | boundary = make_shared<sphere>(point3(0, 0, 0), 5000, make_shared<dielectric>(1.5)); |
2827 | | - objects.add(make_shared<constant_medium>( |
2828 | | - boundary, .0001, make_shared<solid_color>(1,1,1))); |
| 2813 | + objects.add(make_shared<constant_medium>(boundary, .0001, color(1,1,1))); |
2829 | 2814 |
|
2830 | 2815 | auto emat = make_shared<lambertian>(make_shared<image_texture>("earthmap.jpg")); |
2831 | 2816 | objects.add(make_shared<sphere>(point3(400,200,400), 100, emat)); |
2832 | 2817 | auto pertext = make_shared<noise_texture>(0.1); |
2833 | 2818 | objects.add(make_shared<sphere>(point3(220,280,300), 80, make_shared<lambertian>(pertext))); |
2834 | 2819 |
|
2835 | 2820 | hittable_list boxes2; |
2836 | | - auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
| 2821 | + auto white = make_shared<lambertian>(color(.73, .73, .73)); |
2837 | 2822 | int ns = 1000; |
2838 | 2823 | for (int j = 0; j < ns; j++) { |
2839 | 2824 | boxes2.add(make_shared<sphere>(point3::random(0,165), 10, white)); |
|
0 commit comments