|
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));
|
|
2540 | 2523 | class constant_medium : public hittable {
|
2541 | 2524 | public:
|
2542 | 2525 | constant_medium(shared_ptr<hittable> b, double d, shared_ptr<texture> a)
|
2543 |
| - : boundary(b), neg_inv_density(-1/d) |
2544 |
| - { |
2545 |
| - phase_function = make_shared<isotropic>(a); |
2546 |
| - } |
| 2526 | + : boundary(b), |
| 2527 | + neg_inv_density(-1/d), |
| 2528 | + phase_function(make_shared<isotropic>(a)) |
| 2529 | + {} |
| 2530 | + |
| 2531 | + constant_medium(shared_ptr<hittable> b, double d, color c) |
| 2532 | + : boundary(b), |
| 2533 | + neg_inv_density(-1/d), |
| 2534 | + phase_function(make_shared<isotropic>(color(c))) |
| 2535 | + {} |
2547 | 2536 |
|
2548 | 2537 | virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const;
|
2549 | 2538 |
|
|
2658 | 2647 | hittable_list cornell_smoke() {
|
2659 | 2648 | hittable_list objects;
|
2660 | 2649 |
|
2661 |
| - auto red = make_shared<lambertian>(make_shared<solid_color>(.65, .05, .05)); |
2662 |
| - auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
2663 |
| - auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15)); |
2664 |
| - auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7)); |
| 2650 | + auto red = make_shared<lambertian>(color(.65, .05, .05)); |
| 2651 | + auto white = make_shared<lambertian>(color(.73, .73, .73)); |
| 2652 | + auto green = make_shared<lambertian>(color(.12, .45, .15)); |
| 2653 | + auto light = make_shared<diffuse_light>(color(7, 7, 7)); |
2665 | 2654 |
|
2666 | 2655 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
|
2667 | 2656 | objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
|
|
2678 | 2667 | box2 = make_shared<rotate_y>(box2, -18);
|
2679 | 2668 | box2 = make_shared<translate>(box2, vec3(130,0,65));
|
2680 | 2669 |
|
2681 |
| - objects.add(make_shared<constant_medium>(box1, 0.01, make_shared<solid_color>(0,0,0))); |
2682 |
| - objects.add(make_shared<constant_medium>(box2, 0.01, make_shared<solid_color>(1,1,1))); |
| 2670 | + objects.add(make_shared<constant_medium>(box1, 0.01, color(0,0,0))); |
| 2671 | + objects.add(make_shared<constant_medium>(box2, 0.01, color(1,1,1))); |
2683 | 2672 |
|
2684 | 2673 | return objects;
|
2685 | 2674 | }
|
|
2707 | 2696 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2708 | 2697 | hittable_list final_scene() {
|
2709 | 2698 | hittable_list boxes1;
|
2710 |
| - auto ground = make_shared<lambertian>(make_shared<solid_color>(0.48, 0.83, 0.53)); |
| 2699 | + auto ground = make_shared<lambertian>(color(0.48, 0.83, 0.53)); |
2711 | 2700 |
|
2712 | 2701 | const int boxes_per_side = 20;
|
2713 | 2702 | for (int i = 0; i < boxes_per_side; i++) {
|
|
2728 | 2717 |
|
2729 | 2718 | objects.add(make_shared<bvh_node>(boxes1, 0, 1));
|
2730 | 2719 |
|
2731 |
| - auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7)); |
| 2720 | + auto light = make_shared<diffuse_light>(color(7, 7, 7)); |
2732 | 2721 | objects.add(make_shared<xz_rect>(123, 423, 147, 412, 554, light));
|
2733 | 2722 |
|
2734 | 2723 | auto center1 = point3(400, 400, 200);
|
2735 | 2724 | auto center2 = center1 + vec3(30,0,0);
|
2736 |
| - auto moving_sphere_material = |
2737 |
| - make_shared<lambertian>(make_shared<solid_color>(0.7, 0.3, 0.1)); |
| 2725 | + auto moving_sphere_material = make_shared<lambertian>(color(0.7, 0.3, 0.1)); |
2738 | 2726 | objects.add(make_shared<moving_sphere>(center1, center2, 0, 1, 50, moving_sphere_material));
|
2739 | 2727 |
|
2740 | 2728 | objects.add(make_shared<sphere>(point3(260, 150, 45), 50, make_shared<dielectric>(1.5)));
|
|
2744 | 2732 |
|
2745 | 2733 | auto boundary = make_shared<sphere>(point3(360,150,145), 70, make_shared<dielectric>(1.5));
|
2746 | 2734 | objects.add(boundary);
|
2747 |
| - objects.add(make_shared<constant_medium>( |
2748 |
| - boundary, 0.2, make_shared<solid_color>(0.2, 0.4, 0.9) |
2749 |
| - )); |
| 2735 | + objects.add(make_shared<constant_medium>(boundary, 0.2, color(0.2, 0.4, 0.9))); |
2750 | 2736 | boundary = make_shared<sphere>(point3(0, 0, 0), 5000, make_shared<dielectric>(1.5));
|
2751 |
| - objects.add(make_shared<constant_medium>( |
2752 |
| - boundary, .0001, make_shared<solid_color>(1,1,1))); |
| 2737 | + objects.add(make_shared<constant_medium>(boundary, .0001, color(1,1,1))); |
2753 | 2738 |
|
2754 | 2739 | auto emat = make_shared<lambertian>(make_shared<image_texture>("earthmap.jpg"));
|
2755 | 2740 | objects.add(make_shared<sphere>(point3(400,200,400), 100, emat));
|
2756 | 2741 | auto pertext = make_shared<noise_texture>(0.1);
|
2757 | 2742 | objects.add(make_shared<sphere>(point3(220,280,300), 80, make_shared<lambertian>(pertext)));
|
2758 | 2743 |
|
2759 | 2744 | hittable_list boxes2;
|
2760 |
| - auto white = make_shared<lambertian>(make_shared<solid_color>(.73, .73, .73)); |
| 2745 | + auto white = make_shared<lambertian>(color(.73, .73, .73)); |
2761 | 2746 | int ns = 1000;
|
2762 | 2747 | for (int j = 0; j < ns; j++) {
|
2763 | 2748 | boxes2.add(make_shared<sphere>(point3::random(0,165), 10, white));
|
|
0 commit comments