|
938 | 938 | virtual color value(double u, double v, const point3& p) const = 0;
|
939 | 939 | };
|
940 | 940 |
|
941 |
| - class constant_texture : public texture { |
| 941 | + class solid_color : public texture { |
942 | 942 | public:
|
943 |
| - constant_texture() {} |
944 |
| - constant_texture(color c) : solid_color(c) {} |
| 943 | + solid_color() {} |
| 944 | + solid_color(color c) : color_value(c) {} |
945 | 945 |
|
946 |
| - virtual color value(double u, double v, const point3& p) const { |
947 |
| - return solid_color; |
| 946 | + solid_color(double red, double green, double blue) |
| 947 | + : solid_color(color(red,green,blue)) {} |
| 948 | + |
| 949 | + virtual color value(double u, double v, const vec3& p) const { |
| 950 | + return color_value; |
948 | 951 | }
|
949 | 952 |
|
950 |
| - public: |
951 |
| - color solid_color; |
| 953 | + private: |
| 954 | + color color_value; |
952 | 955 | };
|
953 | 956 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
954 | 957 | [Listing [texture]: <kbd>[texture.h]</kbd> A texture class]
|
955 | 958 |
|
956 | 959 | <div class='together'>
|
957 |
| -Now we can make textured materials by replacing the `color solid_color` with a texture pointer: |
| 960 | +Now we can make textured materials by replacing the `const color& a` with a texture pointer: |
958 | 961 |
|
959 | 962 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
960 | 963 | class lambertian : public material {
|
|
991 | 994 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
992 | 995 | [Listing [lam-solid]: <kbd>[main.cc]</kbd> Lambertian material with solid color]
|
993 | 996 |
|
994 |
| -now you should replace the `color(...)` with `make_shared<constant_texture>(color(...))` |
| 997 | +now you should replace the `color(...)` with `make_shared<solid_color>(...)` |
995 | 998 |
|
996 | 999 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
997 |
| - ...make_shared<lambertian>(make_shared<constant_texture>(color(0.5, 0.5, 0.5))) |
| 1000 | + ...make_shared<lambertian>(make_shared<solid_color>(0.5, 0.5, 0.5)) |
998 | 1001 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
999 | 1002 | [Listing [lam-textured]: <kbd>[main.cc]</kbd> Lambertian material with texture]
|
1000 | 1003 | </div>
|
|
1037 | 1040 |
|
1038 | 1041 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1039 | 1042 | auto checker = make_shared<checker_texture>(
|
1040 |
| - make_shared<constant_texture>(color(0.2, 0.3, 0.1)), |
1041 |
| - make_shared<constant_texture>(color(0.9, 0.9, 0.9)) |
| 1043 | + make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
1042 | 1044 | );
|
1043 | 1045 |
|
1044 | 1046 | world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker)));
|
|
1066 | 1068 | hittable_list objects;
|
1067 | 1069 |
|
1068 | 1070 | auto checker = make_shared<checker_texture>(
|
1069 |
| - make_shared<constant_texture>(color(0.2, 0.3, 0.1)), |
1070 |
| - make_shared<constant_texture>(color(0.9, 0.9, 0.9)) |
| 1071 | + make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
1071 | 1072 | );
|
1072 | 1073 |
|
1073 | 1074 | objects.add(make_shared<sphere>(point3(0,-10, 0), 10, make_shared<lambertian>(checker)));
|
|
2037 | 2038 | objects.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(pertext)));
|
2038 | 2039 | objects.add(make_shared<sphere>(point3(0,2,0), 2, make_shared<lambertian>(pertext)));
|
2039 | 2040 |
|
2040 |
| - auto difflight = make_shared<diffuse_light>(make_shared<constant_texture>(color(4,4,4))); |
| 2041 | + auto difflight = make_shared<diffuse_light>(make_shared<solid_color>(4,4,4)); |
2041 | 2042 | objects.add(make_shared<sphere>(point3(0,7,0), 2, difflight));
|
2042 | 2043 | objects.add(make_shared<xy_rect>(3, 5, 1, 3, -2, difflight));
|
2043 | 2044 |
|
|
2175 | 2176 | hittable_list cornell_box() {
|
2176 | 2177 | hittable_list objects;
|
2177 | 2178 |
|
2178 |
| - auto red = make_shared<lambertian>(make_shared<constant_texture>(color(.65, .05, .05))); |
2179 |
| - auto white = make_shared<lambertian>(make_shared<constant_texture>(color(.73, .73, .73))); |
2180 |
| - auto green = make_shared<lambertian>(make_shared<constant_texture>(color(.12, .45, .15))); |
2181 |
| - auto light = make_shared<diffuse_light>(make_shared<constant_texture>(color(15, 15, 15))); |
| 2179 | + auto red = make_shared<lambertian>(make_shared<solid_color>(.65, .05, .05)); |
| 2180 | + auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
| 2181 | + auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
| 2182 | + auto light = make_shared<diffuse_light>(make_shared<solid_color>(15, 15, 15)); |
2182 | 2183 |
|
2183 | 2184 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
|
2184 | 2185 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
|
|
2263 | 2264 | hittable_list cornell_box() {
|
2264 | 2265 | hittable_list objects;
|
2265 | 2266 |
|
2266 |
| - auto red = make_shared<lambertian>(make_shared<constant_texture>(color(.65, .05, .05))); |
2267 |
| - auto white = make_shared<lambertian>(make_shared<constant_texture>(color(.73, .73, .73))); |
2268 |
| - auto green = make_shared<lambertian>(make_shared<constant_texture>(color(.12, .45, .15))); |
2269 |
| - auto light = make_shared<diffuse_light>(make_shared<constant_texture>(color(15, 15, 15))); |
| 2267 | + auto red = make_shared<lambertian>(make_shared<solid_color>(.65, .05, .05)); |
| 2268 | + auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
| 2269 | + auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
| 2270 | + auto light = make_shared<diffuse_light>(make_shared<solid_color>(15, 15, 15)); |
2270 | 2271 |
|
2271 | 2272 |
|
2272 | 2273 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
|
2761 | 2762 | hittable_list cornell_smoke() {
|
2762 | 2763 | hittable_list objects;
|
2763 | 2764 |
|
2764 |
| - auto red = make_shared<lambertian>(make_shared<constant_texture>(color(.65, .05, .05))); |
2765 |
| - auto white = make_shared<lambertian>(make_shared<constant_texture>(color(.73, .73, .73))); |
2766 |
| - auto green = make_shared<lambertian>(make_shared<constant_texture>(color(.12, .45, .15))); |
2767 |
| - auto light = make_shared<diffuse_light>(make_shared<constant_texture>(color(7, 7, 7))); |
| 2765 | + auto red = make_shared<lambertian>(make_shared<solid_color>(.65, .05, .05)); |
| 2766 | + auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
| 2767 | + auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
| 2768 | + auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7)); |
2768 | 2769 |
|
2769 | 2770 | objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
|
2770 | 2771 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
|
|
2781 | 2782 | box2 = make_shared<rotate_y>(box2, -18);
|
2782 | 2783 | box2 = make_shared<translate>(box2, vec3(130,0,65));
|
2783 | 2784 |
|
2784 |
| - objects.add( |
2785 |
| - make_shared<constant_medium>(box1, 0.01, make_shared<constant_texture>(color(0,0,0)))); |
2786 |
| - objects.add( |
2787 |
| - make_shared<constant_medium>(box2, 0.01, make_shared<constant_texture>(color(1,1,1)))); |
| 2785 | + objects.add(make_shared<constant_medium>(box1, 0.01, make_shared<solid_color>(0,0,0))); |
| 2786 | + objects.add(make_shared<constant_medium>(box2, 0.01, make_shared<solid_color>(1,1,1))); |
2788 | 2787 |
|
2789 | 2788 | return objects;
|
2790 | 2789 | }
|
|
2816 | 2815 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2817 | 2816 | hittable_list final_scene() {
|
2818 | 2817 | hittable_list boxes1;
|
2819 |
| - auto ground = |
2820 |
| - make_shared<lambertian>(make_shared<constant_texture>(color(0.48, 0.83, 0.53))); |
| 2818 | + auto ground = make_shared<lambertian>(make_shared<solid_color>(0.48, 0.83, 0.53)); |
2821 | 2819 |
|
2822 | 2820 | const int boxes_per_side = 20;
|
2823 | 2821 | for (int i = 0; i < boxes_per_side; i++) {
|
|
2838 | 2836 |
|
2839 | 2837 | objects.add(make_shared<bvh_node>(boxes1, 0, 1));
|
2840 | 2838 |
|
2841 |
| - auto light = make_shared<diffuse_light>(make_shared<constant_texture>(color(7, 7, 7))); |
| 2839 | + auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7)); |
2842 | 2840 | objects.add(make_shared<xz_rect>(123, 423, 147, 412, 554, light));
|
2843 | 2841 |
|
2844 | 2842 | auto center1 = point3(400, 400, 200);
|
2845 | 2843 | auto center2 = center1 + vec3(30,0,0);
|
2846 | 2844 | auto moving_sphere_material =
|
2847 |
| - make_shared<lambertian>(make_shared<constant_texture>(color(0.7, 0.3, 0.1))); |
| 2845 | + make_shared<lambertian>(make_shared<solid_color>(0.7, 0.3, 0.1)); |
2848 | 2846 | objects.add(make_shared<moving_sphere>(center1, center2, 0, 1, 50, moving_sphere_material));
|
2849 | 2847 |
|
2850 | 2848 | objects.add(make_shared<sphere>(point3(260, 150, 45), 50, make_shared<dielectric>(1.5)));
|
|
2855 | 2853 | auto boundary = make_shared<sphere>(point3(360,150,145), 70, make_shared<dielectric>(1.5));
|
2856 | 2854 | objects.add(boundary);
|
2857 | 2855 | objects.add(make_shared<constant_medium>(
|
2858 |
| - boundary, 0.2, make_shared<constant_texture>(color(0.2, 0.4, 0.9)) |
| 2856 | + boundary, 0.2, make_shared<solid_color>(0.2, 0.4, 0.9) |
2859 | 2857 | ));
|
2860 | 2858 | boundary = make_shared<sphere>(point3(0, 0, 0), 5000, make_shared<dielectric>(1.5));
|
2861 | 2859 | objects.add(make_shared<constant_medium>(
|
2862 |
| - boundary, .0001, make_shared<constant_texture>(color(1,1,1)))); |
| 2860 | + boundary, .0001, make_shared<solid_color>(1,1,1))); |
2863 | 2861 |
|
2864 | 2862 | int nx, ny, nn;
|
2865 | 2863 | auto tex_data = stbi_load("earthmap.jpg", &nx, &ny, &nn, 0);
|
|
2869 | 2867 | objects.add(make_shared<sphere>(point3(220,280,300), 80, make_shared<lambertian>(pertext)));
|
2870 | 2868 |
|
2871 | 2869 | hittable_list boxes2;
|
2872 |
| - auto white = make_shared<lambertian>(make_shared<constant_texture>(color(.73, .73, .73))); |
| 2870 | + auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
2873 | 2871 | int ns = 1000;
|
2874 | 2872 | for (int j = 0; j < ns; j++) {
|
2875 | 2873 | boxes2.add(make_shared<sphere>(point3::random(0,165), 10, white));
|
|
0 commit comments