|
777 | 777 |
|
778 | 778 | shared_ptr<hittable> box2 = make_shared<box>(point3(0,0,0), point3(165,165,165), white); |
779 | 779 | box2 = make_shared<rotate_y>(box2, -18); |
780 | | - box2 = make_shared<translate>(box2, vec3(130,0,65); |
| 780 | + box2 = make_shared<translate>(box2, vec3(130,0,65)); |
781 | 781 | world.add(box2); |
782 | 782 |
|
783 | 783 | point3 lookfrom(278, 278, -800); |
|
857 | 857 | virtual bool scatter( |
858 | 858 | const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf |
859 | 859 | ) const { |
860 | | - point3 target = rec.p + rec.normal + random_unit_vector(); |
861 | | - scattered = ray(rec.p, unit_vector(target-rec.p), r_in.time()); |
| 860 | + auto direction = rec.normal + random_unit_vector(); |
| 861 | + scattered = ray(rec.p, unit_vector(direction), r_in.time()); |
862 | 862 | alb = albedo->value(rec.u, rec.v, rec.p); |
863 | 863 | pdf = dot(rec.normal, scattered.direction()) / pi; |
864 | 864 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
928 | 928 | randomly from the hemisphere above the surface. This would be $p(direction) = \frac{1}{2\pi}$. |
929 | 929 |
|
930 | 930 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
931 | | - bool scatter( |
| 931 | + virtual bool scatter( |
932 | 932 | const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf |
933 | 933 | ) const { |
934 | | - vec3 direction = random_in_hemisphere(rec.normal); |
| 934 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 935 | + auto direction = random_in_hemisphere(rec.normal); |
| 936 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
935 | 937 | scattered = ray(rec.p, unit_vector(direction), r_in.time()); |
936 | 938 | alb = albedo->value(rec.u, rec.v, rec.p); |
| 939 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
937 | 940 | pdf = 0.5 / pi; |
| 941 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
938 | 942 | return true; |
939 | 943 | } |
940 | 944 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
1292 | 1296 | We can rewrite our Lambertian material using this to get: |
1293 | 1297 |
|
1294 | 1298 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1295 | | - bool scatter( |
| 1299 | + virtual bool scatter( |
1296 | 1300 | const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf |
1297 | 1301 | ) const { |
1298 | 1302 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1299 | 1303 | onb uvw; |
1300 | 1304 | uvw.build_from_w(rec.normal); |
1301 | | - vec3 direction = uvw.local(random_cosine_direction()); |
| 1305 | + auto direction = uvw.local(random_cosine_direction()); |
1302 | 1306 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1303 | 1307 | scattered = ray(rec.p, unit_vector(direction), r_in.time()); |
1304 | 1308 | alb = albedo->value(rec.u, rec.v, rec.p); |
|
1393 | 1397 | return emitted; |
1394 | 1398 |
|
1395 | 1399 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1396 | | - auto on_light = vec3(random_double(213,343), 554, random_double(227,332)); |
| 1400 | + auto on_light = point3(random_double(213,343), 554, random_double(227,332)); |
1397 | 1401 | auto to_light = on_light - rec.p; |
1398 | 1402 | auto distance_squared = to_light.length_squared(); |
1399 | | - to_light.make_unit_vector(); |
| 1403 | + to_light = unit_vector(to_light); |
1400 | 1404 |
|
1401 | 1405 | if (dot(to_light, rec.normal) < 0) |
1402 | 1406 | return emitted; |
|
1952 | 1956 | lambertian(shared_ptr<texture> a) : albedo(a) {} |
1953 | 1957 |
|
1954 | 1958 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1955 | | - bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const { |
| 1959 | + virtual bool scatter( |
| 1960 | + const ray& r_in, const hit_record& rec, scatter_record& srec |
| 1961 | + ) const { |
1956 | 1962 | srec.is_specular = false; |
1957 | 1963 | srec.attenuation = albedo->value(rec.u, rec.v, rec.p); |
1958 | 1964 | srec.pdf_ptr = new cosine_pdf(rec.normal); |
|
0 commit comments