|
854 | 854 | virtual bool scatter(
|
855 | 855 | const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
|
856 | 856 | ) const {
|
857 |
| - point3 target = rec.p + rec.normal + random_unit_vector(); |
858 |
| - scattered = ray(rec.p, unit_vector(target-rec.p), r_in.time()); |
| 857 | + auto direction = rec.normal + random_unit_vector(); |
| 858 | + scattered = ray(rec.p, unit_vector(direction), r_in.time()); |
859 | 859 | alb = albedo->value(rec.u, rec.v, rec.p);
|
860 | 860 | pdf = dot(rec.normal, scattered.direction()) / pi;
|
861 | 861 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
|
925 | 925 | randomly from the hemisphere above the surface. This would be $p(direction) = \frac{1}{2\pi}$.
|
926 | 926 |
|
927 | 927 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
928 |
| - bool scatter( |
| 928 | + virtual bool scatter( |
929 | 929 | const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
|
930 | 930 | ) const {
|
931 |
| - vec3 direction = random_in_hemisphere(rec.normal); |
| 931 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 932 | + auto direction = random_in_hemisphere(rec.normal); |
| 933 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
932 | 934 | scattered = ray(rec.p, unit_vector(direction), r_in.time());
|
933 | 935 | alb = albedo->value(rec.u, rec.v, rec.p);
|
| 936 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
934 | 937 | pdf = 0.5 / pi;
|
| 938 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
935 | 939 | return true;
|
936 | 940 | }
|
937 | 941 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1287 | 1291 | We can rewrite our Lambertian material using this to get:
|
1288 | 1292 |
|
1289 | 1293 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1290 |
| - bool scatter( |
| 1294 | + virtual bool scatter( |
1291 | 1295 | const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
|
1292 | 1296 | ) const {
|
1293 | 1297 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1294 | 1298 | onb uvw;
|
1295 | 1299 | uvw.build_from_w(rec.normal);
|
1296 |
| - vec3 direction = uvw.local(random_cosine_direction()); |
| 1300 | + auto direction = uvw.local(random_cosine_direction()); |
1297 | 1301 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1298 | 1302 | scattered = ray(rec.p, unit_vector(direction), r_in.time());
|
1299 | 1303 | alb = albedo->value(rec.u, rec.v, rec.p);
|
|
1944 | 1948 | lambertian(shared_ptr<texture> a) : albedo(a) {}
|
1945 | 1949 |
|
1946 | 1950 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1947 |
| - bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const { |
| 1951 | + virtual bool scatter( |
| 1952 | + const ray& r_in, const hit_record& rec, scatter_record& srec |
| 1953 | + ) const { |
1948 | 1954 | srec.is_specular = false;
|
1949 | 1955 | srec.attenuation = albedo->value(rec.u, rec.v, rec.p);
|
1950 | 1956 | srec.pdf_ptr = new cosine_pdf(rec.normal);
|
|
0 commit comments