diff --git a/books/RayTracingInOneWeekend.html b/books/RayTracingInOneWeekend.html index cf45109e..d26b2664 100644 --- a/books/RayTracingInOneWeekend.html +++ b/books/RayTracingInOneWeekend.html @@ -1114,7 +1114,7 @@ class sphere : public hittable { public: - sphere(const point3& _center, double _radius) : center(_center), radius(_radius) {} + sphere(const point3& center, double radius) : center(center), radius(radius) {} bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) const override { vec3 oc = center - r.origin(); @@ -1551,7 +1551,7 @@ interval() : min(+infinity), max(-infinity) {} // Default interval is empty - interval(double _min, double _max) : min(_min), max(_max) {} + interval(double min, double max) : min(min), max(max) {} double size() const { return max - min; @@ -2794,8 +2794,8 @@ class sphere : public hittable { public: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - sphere(const point3& _center, double _radius, shared_ptr _material) - : center(_center), radius(_radius), mat(_material) {} + sphere(const point3& center, double radius, shared_ptr mat) + : center(center), radius(radius), mat(mat) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ bool hit(const ray& r, interval ray_t, hit_record& rec) const override { @@ -2844,7 +2844,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ Highlight class lambertian : public material { public: - lambertian(const color& a) : albedo(a) {} + lambertian(const color& albedo) : albedo(albedo) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -2896,7 +2896,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class lambertian : public material { public: - lambertian(const color& a) : albedo(a) {} + lambertian(const color& albedo) : albedo(albedo) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -2964,7 +2964,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ Highlight class metal : public material { public: - metal(const color& a) : albedo(a) {} + metal(const color& albedo) : albedo(albedo) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -3099,7 +3099,7 @@ class metal : public material { public: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - metal(const color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {} + metal(const color& albedo, double fuzz) : albedo(albedo), fuzz(fuzz < 1 ? fuzz : 1) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) @@ -3252,12 +3252,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ Highlight class dielectric : public material { public: - dielectric(double index_of_refraction) : ir(index_of_refraction) {} + dielectric(double ref_index) : ref_index(ref_index) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { attenuation = color(1.0, 1.0, 1.0); - double refraction_ratio = rec.front_face ? (1.0/ir) : ir; + double refraction_ratio = rec.front_face ? (1.0/ref_index) : ref_index; vec3 unit_direction = unit_vector(r_in.direction()); vec3 refracted = refract(unit_direction, rec.normal, refraction_ratio); @@ -3267,7 +3267,8 @@ } private: - double ir; // Index of Refraction + double ref_index; // Refractive index in vacuum or air, or the ratio of the material's + // refractive index over the refractive index of the enclosing media }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [dielectric-always-refract]: [material.h] @@ -3365,12 +3366,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class dielectric : public material { public: - dielectric(double index_of_refraction) : ir(index_of_refraction) {} + dielectric(double ref_index) : ref_index(ref_index) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { attenuation = color(1.0, 1.0, 1.0); - double refraction_ratio = rec.front_face ? (1.0/ir) : ir; + double refraction_ratio = rec.front_face ? (1.0/ref_index) : ref_index; vec3 unit_direction = unit_vector(r_in.direction()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight @@ -3391,7 +3392,8 @@ } private: - double ir; // Index of Refraction + double ref_index; // Refractive index in vacuum or air, or the ratio of the material's + // refractive index over the refractive index of the enclosing media }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [dielectric-with-refraction]: [material.h] @@ -3433,12 +3435,12 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class dielectric : public material { public: - dielectric(double index_of_refraction) : ir(index_of_refraction) {} + dielectric(double ref_index) : ref_index(ref_index) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { attenuation = color(1.0, 1.0, 1.0); - double refraction_ratio = rec.front_face ? (1.0/ir) : ir; + double refraction_ratio = rec.front_face ? (1.0/ref_index) : ref_index; vec3 unit_direction = unit_vector(r_in.direction()); double cos_theta = fmin(dot(-unit_direction, rec.normal), 1.0); @@ -3459,7 +3461,8 @@ } private: - double ir; // Index of Refraction + double ref_index; // Refractive index in vacuum or air, or the ratio of the material's + // refractive index over the refractive index of the enclosing media ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight diff --git a/books/RayTracingTheNextWeek.html b/books/RayTracingTheNextWeek.html index c2c4c307..1941c141 100644 --- a/books/RayTracingTheNextWeek.html +++ b/books/RayTracingTheNextWeek.html @@ -178,15 +178,15 @@ public: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight // Stationary Sphere - sphere(const point3& _center, double _radius, shared_ptr _material) - : center1(_center), radius(_radius), mat(_material), is_moving(false) {} + sphere(const point3& center, double radius, shared_ptr mat) + : center1(center), radius(radius), mat(mat), is_moving(false) {} // Moving Sphere - sphere(const point3& _center1, const point3& _center2, double _radius, - shared_ptr _material) - : center1(_center1), radius(_radius), mat(_material), is_moving(true) + sphere(const point3& center1, const point3& center2, double radius, + shared_ptr mat) + : center1(center1), radius(radius), mat(mat), is_moving(true) { - center_vec = _center2 - _center1; + center_vec = center2 - center1; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ @@ -608,8 +608,8 @@ aabb() {} // The default AABB is empty, since intervals are empty by default. - aabb(const interval& _x, const interval& _y, const interval& _z) - : x(_x), y(_y), z(_z) {} + aabb(const interval& x, const interval& y, const interval& z) + : x(x), y(y), z(z) {} aabb(const point3& a, const point3& b) { // Treat the two points a and b as extrema for the bounding box, so we don't require a @@ -723,8 +723,8 @@ public: // Stationary Sphere ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - sphere(const point3& _center, double _radius, shared_ptr _material) - : center1(_center), radius(_radius), mat(_material), is_moving(false) + sphere(const point3& center, double radius, shared_ptr mat) + : center1(center), radius(radius), mat(mat), is_moving(false) { auto rvec = vec3(radius, radius, radius); bbox = aabb(center1 - rvec, center1 + rvec); @@ -758,9 +758,9 @@ public: ... // Moving Sphere - sphere(const point3& _center1, const point3& _center2, double _radius, - shared_ptr _material) - : center1(_center1), radius(_radius), mat(_material), is_moving(true) + sphere(const point3& center1, const point3& center2, double radius, + shared_ptr mat) + : center1(center1), radius(radius), mat(mat), is_moving(true) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight auto rvec = vec3(radius, radius, radius); @@ -1215,7 +1215,7 @@ class solid_color : public texture { public: - solid_color(const color& c) : color_value(c) {} + solid_color(const color& albedo) : color_value(albedo) {} solid_color(double red, double green, double blue) : solid_color(color(red,green,blue)) {} @@ -1280,11 +1280,11 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class checker_texture : public texture { public: - checker_texture(double _scale, shared_ptr _even, shared_ptr _odd) - : inv_scale(1.0 / _scale), even(_even), odd(_odd) {} + checker_texture(double scale, shared_ptr even, shared_ptr odd) + : inv_scale(1.0 / scale), even(even), odd(odd) {} - checker_texture(double _scale, const color& c1, const color& c2) - : inv_scale(1.0 / _scale), + checker_texture(double scale, const color& c1, const color& c2) + : inv_scale(1.0 / scale), even(make_shared(c1)), odd(make_shared(c2)) {} @@ -1322,8 +1322,8 @@ class lambertian : public material { public: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - lambertian(const color& a) : albedo(make_shared(a)) {} - lambertian(shared_ptr a) : albedo(a) {} + lambertian(const color& albedo) : tex(make_shared(albedo)) {} + lambertian(shared_ptr tex) : tex(tex) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) @@ -1336,14 +1336,14 @@ scattered = ray(rec.p, scatter_direction, r_in.time()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ return true; } private: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - shared_ptr albedo; + shared_ptr tex; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2128,7 +2128,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - noise_texture(double sc) : scale(sc) {} + noise_texture(double scale) : scale(scale) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ color value(double u, double v, const point3& p) const override { @@ -2320,7 +2320,7 @@ public: noise_texture() {} - noise_texture(double sc) : scale(sc) {} + noise_texture(double scale) : scale(scale) {} color value(double u, double v, const point3& p) const override { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight @@ -2378,7 +2378,7 @@ public: noise_texture() {} - noise_texture(double sc) : scale(sc) {} + noise_texture(double scale) : scale(scale) {} color value(double u, double v, const point3& p) const override { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight @@ -2415,7 +2415,7 @@ public: noise_texture() {} - noise_texture(double sc) : scale(sc) {} + noise_texture(double scale) : scale(scale) {} color value(double u, double v, const point3& p) const override { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight @@ -2485,8 +2485,8 @@ class aabb { public: ... - aabb(const interval& _x, const interval& _y, const interval& _z) - : x(_x), y(_y), z(_z) + aabb(const interval& x, const interval& y, const interval& z) + : x(x), y(y), z(z) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight { pad_to_minimums(); @@ -2540,8 +2540,8 @@ class quad : public hittable { public: - quad(const point3& _Q, const vec3& _u, const vec3& _v, shared_ptr m) - : Q(_Q), u(_u), v(_v), mat(m) + quad(const point3& Q, const vec3& u, const vec3& v, shared_ptr mat) + : Q(Q), u(u), v(v), mat(mat) { set_bounding_box(); } @@ -2665,8 +2665,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class quad : public hittable { public: - quad(const point3& _Q, const vec3& _u, const vec3& _v, shared_ptr m) - : Q(_Q), u(_u), v(_v), mat(m) + quad(const point3& Q, const vec3& u, const vec3& v, shared_ptr mat) + : Q(Q), u(u), v(v), mat(mat) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight auto n = cross(u, v); @@ -2779,8 +2779,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class quad : public hittable { public: - quad(const point3& _Q, const vec3& _u, const vec3& _v, shared_ptr m) - : Q(_Q), u(_u), v(_v), mat(m) + quad(const point3& Q, const vec3& u, const vec3& v, shared_ptr mat) + : Q(Q), u(u), v(v), mat(mat) { auto n = cross(u, v); normal = unit_vector(n); @@ -3078,8 +3078,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class diffuse_light : public material { public: - diffuse_light(shared_ptr a) : emit(a) {} - diffuse_light(const color& c) : emit(make_shared(c)) {} + diffuse_light(shared_ptr tex) : tex(tex) {} + diffuse_light(const color& emit) : tex(make_shared(emit)) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -3087,11 +3087,11 @@ } color emitted(double u, double v, const point3& p) const override { - return emit->value(u, v, p); + return tex->value(u, v, p); } private: - shared_ptr emit; + shared_ptr tex; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [diffuse-light]: [material.h] A diffuse light class] @@ -3533,8 +3533,8 @@ class translate : public hittable { public: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - translate(shared_ptr p, const vec3& displacement) - : object(p), offset(displacement) + translate(shared_ptr object, const vec3& offset) + : object(object), offset(offset) { bbox = object->bounding_box() + offset; } @@ -3684,7 +3684,7 @@ $$ z' = \sin(\theta) \cdot x + \cos(\theta) \cdot z $$
-We can now create a class for y-rotation: +We can now create a class for y-rotation. Let's tackle the hit function first: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class rotate_y : public hittable { @@ -3735,7 +3735,7 @@ class rotate_y : public hittable { public: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - rotate_y(shared_ptr p, double angle) : object(p) { + rotate_y(shared_ptr object, double angle) : object(object) { auto radians = degrees_to_radians(angle); sin_theta = sin(radians); cos_theta = cos(radians); @@ -3947,18 +3947,18 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class isotropic : public material { public: - isotropic(const color& c) : albedo(make_shared(c)) {} - isotropic(shared_ptr a) : albedo(a) {} + isotropic(const color& c) : tex(make_shared(c)) {} + isotropic(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { scattered = ray(rec.p, random_unit_vector(), r_in.time()); - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); return true; } private: - shared_ptr albedo; + shared_ptr tex; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [isotropic-class]: [material.h] The isotropic class] diff --git a/books/RayTracingTheRestOfYourLife.html b/books/RayTracingTheRestOfYourLife.html index 69357649..53fcf435 100644 --- a/books/RayTracingTheRestOfYourLife.html +++ b/books/RayTracingTheRestOfYourLife.html @@ -1666,8 +1666,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class lambertian : public material { public: - lambertian(const color& a) : albedo(make_shared(a)) {} - lambertian(shared_ptr a) : albedo(a) {} + lambertian(const color& albedo) : tex(make_shared(albedo)) {} + lambertian(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -1678,7 +1678,7 @@ scatter_direction = rec.normal; scattered = ray(rec.p, scatter_direction, r_in.time()); - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); return true; } @@ -1691,7 +1691,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ private: - shared_ptr albedo; + shared_ptr tex; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [class-lambertian-impsample]: [material.h] @@ -1836,8 +1836,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class lambertian : public material { public: - lambertian(const color& a) : albedo(make_shared(a)) {} - lambertian(shared_ptr a) : albedo(a) {} + lambertian(const color& albedo) : tex(make_shared(albedo)) {} + lambertian(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -1850,7 +1850,7 @@ scatter_direction = rec.normal; scattered = ray(rec.p, scatter_direction, r_in.time()); - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); return true; } @@ -2296,7 +2296,7 @@ scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight pdf = dot(uvw.w(), scattered.direction()) / pi; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ @@ -2326,15 +2326,15 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class isotropic : public material { public: - isotropic(const color& c) : albedo(make_shared(c)) {} - isotropic(shared_ptr a) : albedo(a) {} + isotropic(const color& albedo) : tex(make_shared(albedo)) {} + isotropic(shared_ptr tex) : tex(tex) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight bool scatter( const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered, double& pdf ) const override { - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ scattered = ray(rec.p, random_unit_vector(), r_in.time()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight @@ -2352,7 +2352,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ private: - shared_ptr albedo; + shared_ptr tex; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [class-isotropic-impsample]: [material.h] @@ -2707,8 +2707,8 @@ ... class hittable_pdf : public pdf { public: - hittable_pdf(const hittable& _objects, const point3& _origin) - : objects(_objects), origin(_origin) + hittable_pdf(const hittable& objects, const point3& origin) + : objects(objects), origin(origin) {} double value(const vec3& direction) const override { @@ -2759,8 +2759,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class quad : public hittable { public: - quad(const point3& _Q, const vec3& _u, const vec3& _v, shared_ptr m) - : Q(_Q), u(_u), v(_v), mat(m) + quad(const point3& Q, const vec3& u, const vec3& v, shared_ptr mat) + : Q(Q), u(u), v(v), mat(mat) { auto n = cross(u, v); normal = unit_vector(n); @@ -3170,13 +3170,13 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class lambertian : public material { public: - lambertian(const color& a) : albedo(make_shared(a)) {} - lambertian(shared_ptr a) : albedo(a) {} + lambertian(const color& albedo) : tex(make_shared(albedo)) {} + lambertian(shared_ptr tex) : tex(tex) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const override { - srec.attenuation = albedo->value(rec.u, rec.v, rec.p); + srec.attenuation = tex->value(rec.u, rec.v, rec.p); srec.pdf_ptr = make_shared(rec.normal); srec.skip_pdf = false; return true; @@ -3189,7 +3189,7 @@ } private: - shared_ptr albedo; + shared_ptr tex; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [lambertian-scatter]: [material.h] New lambertian scatter() method] @@ -3202,13 +3202,13 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class isotropic : public material { public: - isotropic(const color& c) : albedo(make_shared(c)) {} - isotropic(shared_ptr a) : albedo(a) {} + isotropic(const color& albedo) : tex(make_shared(albedo)) {} + isotropic(shared_ptr tex) : tex(tex) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const override { - srec.attenuation = albedo->value(rec.u, rec.v, rec.p); + srec.attenuation = tex->value(rec.u, rec.v, rec.p); srec.pdf_ptr = make_shared(); srec.skip_pdf = false; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ @@ -3221,7 +3221,7 @@ } private: - shared_ptr albedo; + shared_ptr tex; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [isotropic-scatter]: [material.h] New isotropic scatter() method] @@ -3294,7 +3294,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class metal : public material { public: - metal(const color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {} + metal(const color& albedo, double fuzz) : albedo(albedo), fuzz(fuzz < 1 ? fuzz : 1) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight @@ -3319,7 +3319,7 @@ class dielectric : public material { public: - dielectric(double index_of_refraction) : ir(index_of_refraction) {} + dielectric(double ref_index) : ref_index(ref_index) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight @@ -3328,7 +3328,7 @@ srec.pdf_ptr = nullptr; srec.skip_pdf = true; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ - double refraction_ratio = rec.front_face ? (1.0/ir) : ir; + double refraction_ratio = rec.front_face ? (1.0/ref_index) : ref_index; vec3 unit_direction = unit_vector(r_in.direction()); double cos_theta = fmin(dot(-unit_direction, rec.normal), 1.0); diff --git a/src/InOneWeekend/interval.h b/src/InOneWeekend/interval.h index 95cbca6f..a40ef9d9 100644 --- a/src/InOneWeekend/interval.h +++ b/src/InOneWeekend/interval.h @@ -15,7 +15,7 @@ class interval { interval() : min(+infinity), max(-infinity) {} // Default interval is empty - interval(double _min, double _max) : min(_min), max(_max) {} + interval(double min, double max) : min(min), max(max) {} double size() const { return max - min; diff --git a/src/InOneWeekend/material.h b/src/InOneWeekend/material.h index ee7329c5..cfad7fa4 100644 --- a/src/InOneWeekend/material.h +++ b/src/InOneWeekend/material.h @@ -28,7 +28,7 @@ class material { class lambertian : public material { public: - lambertian(const color& a) : albedo(a) {} + lambertian(const color& albedo) : albedo(albedo) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -50,13 +50,14 @@ class lambertian : public material { class metal : public material { public: - metal(const color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {} + metal(const color& albedo, double fuzz) : albedo(albedo), fuzz(fuzz < 1 ? fuzz : 1) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal); scattered = ray(rec.p, reflected + fuzz*random_in_unit_sphere()); attenuation = albedo; + return (dot(scattered.direction(), rec.normal) > 0); } @@ -68,12 +69,12 @@ class metal : public material { class dielectric : public material { public: - dielectric(double index_of_refraction) : ir(index_of_refraction) {} + dielectric(double ref_index) : ref_index(ref_index) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { attenuation = color(1.0, 1.0, 1.0); - double refraction_ratio = rec.front_face ? (1.0/ir) : ir; + double refraction_ratio = rec.front_face ? (1.0/ref_index) : ref_index; vec3 unit_direction = unit_vector(r_in.direction()); double cos_theta = fmin(dot(-unit_direction, rec.normal), 1.0); @@ -92,7 +93,8 @@ class dielectric : public material { } private: - double ir; // Index of Refraction + double ref_index; // Refractive index in vacuum or air, or the ratio of the material's + // refractive index over the refractive index of the enclosing media static double reflectance(double cosine, double ref_idx) { // Use Schlick's approximation for reflectance. diff --git a/src/InOneWeekend/sphere.h b/src/InOneWeekend/sphere.h index acccfbb1..aa88d0dd 100644 --- a/src/InOneWeekend/sphere.h +++ b/src/InOneWeekend/sphere.h @@ -18,8 +18,8 @@ class sphere : public hittable { public: - sphere(const point3& _center, double _radius, shared_ptr _material) - : center(_center), radius(_radius), mat(_material) {} + sphere(const point3& center, double radius, shared_ptr mat) + : center(center), radius(radius), mat(mat) {} bool hit(const ray& r, interval ray_t, hit_record& rec) const override { vec3 oc = center - r.origin(); diff --git a/src/TheNextWeek/aabb.h b/src/TheNextWeek/aabb.h index 8e00774a..daf7317d 100644 --- a/src/TheNextWeek/aabb.h +++ b/src/TheNextWeek/aabb.h @@ -20,8 +20,8 @@ class aabb { aabb() {} // The default AABB is empty, since intervals are empty by default. - aabb(const interval& _x, const interval& _y, const interval& _z) - : x(_x), y(_y), z(_z) + aabb(const interval& x, const interval& y, const interval& z) + : x(x), y(y), z(z) { pad_to_minimums(); } diff --git a/src/TheNextWeek/constant_medium.h b/src/TheNextWeek/constant_medium.h index 4aa2bb22..3ccb09c1 100644 --- a/src/TheNextWeek/constant_medium.h +++ b/src/TheNextWeek/constant_medium.h @@ -20,12 +20,14 @@ class constant_medium : public hittable { public: - constant_medium(shared_ptr b, double d, shared_ptr a) - : boundary(b), neg_inv_density(-1/d), phase_function(make_shared(a)) + constant_medium(shared_ptr boundary, double density, shared_ptr tex) + : boundary(boundary), neg_inv_density(-1/density), + phase_function(make_shared(tex)) {} - constant_medium(shared_ptr b, double d, const color& c) - : boundary(b), neg_inv_density(-1/d), phase_function(make_shared(c)) + constant_medium(shared_ptr boundary, double density, const color& c) + : boundary(boundary), neg_inv_density(-1/density), + phase_function(make_shared(c)) {} bool hit(const ray& r, interval ray_t, hit_record& rec) const override { diff --git a/src/TheNextWeek/hittable.h b/src/TheNextWeek/hittable.h index 7def7c9d..02232c36 100644 --- a/src/TheNextWeek/hittable.h +++ b/src/TheNextWeek/hittable.h @@ -51,8 +51,8 @@ class hittable { class translate : public hittable { public: - translate(shared_ptr p, const vec3& displacement) - : object(p), offset(displacement) + translate(shared_ptr object, const vec3& offset) + : object(object), offset(offset) { bbox = object->bounding_box() + offset; } @@ -82,7 +82,7 @@ class translate : public hittable { class rotate_y : public hittable { public: - rotate_y(shared_ptr p, double angle) : object(p) { + rotate_y(shared_ptr object, double angle) : object(object) { auto radians = degrees_to_radians(angle); sin_theta = sin(radians); cos_theta = cos(radians); diff --git a/src/TheNextWeek/interval.h b/src/TheNextWeek/interval.h index a8b849a7..333e954b 100644 --- a/src/TheNextWeek/interval.h +++ b/src/TheNextWeek/interval.h @@ -15,7 +15,7 @@ class interval { interval() : min(+infinity), max(-infinity) {} // Default interval is empty - interval(double _min, double _max) : min(_min), max(_max) {} + interval(double min, double max) : min(min), max(max) {} interval(const interval& a, const interval& b) : min(fmin(a.min, b.min)), max(fmax(a.max, b.max)) {} diff --git a/src/TheNextWeek/material.h b/src/TheNextWeek/material.h index 94192cdf..c44184d3 100644 --- a/src/TheNextWeek/material.h +++ b/src/TheNextWeek/material.h @@ -33,8 +33,8 @@ class material { class lambertian : public material { public: - lambertian(const color& a) : albedo(make_shared(a)) {} - lambertian(shared_ptr a) : albedo(a) {} + lambertian(const color& albedo) : tex(make_shared(albedo)) {} + lambertian(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -45,24 +45,25 @@ class lambertian : public material { scatter_direction = rec.normal; scattered = ray(rec.p, scatter_direction, r_in.time()); - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); return true; } private: - shared_ptr albedo; + shared_ptr tex; }; class metal : public material { public: - metal(const color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {} + metal(const color& albedo, double fuzz) : albedo(albedo), fuzz(fuzz < 1 ? fuzz : 1) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal); scattered = ray(rec.p, reflected + fuzz*random_in_unit_sphere(), r_in.time()); attenuation = albedo; + return (dot(scattered.direction(), rec.normal) > 0); } @@ -74,12 +75,12 @@ class metal : public material { class dielectric : public material { public: - dielectric(double index_of_refraction) : ir(index_of_refraction) {} + dielectric(double ref_index) : ref_index(ref_index) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { attenuation = color(1.0, 1.0, 1.0); - double refraction_ratio = rec.front_face ? (1.0/ir) : ir; + double refraction_ratio = rec.front_face ? (1.0/ref_index) : ref_index; vec3 unit_direction = unit_vector(r_in.direction()); double cos_theta = fmin(dot(-unit_direction, rec.normal), 1.0); @@ -98,7 +99,8 @@ class dielectric : public material { } private: - double ir; // Index of Refraction + double ref_index; // Refractive index in vacuum or air, or the ratio of the material's + // refractive index over the refractive index of the enclosing media static double reflectance(double cosine, double ref_idx) { // Use Schlick's approximation for reflectance. @@ -111,8 +113,8 @@ class dielectric : public material { class diffuse_light : public material { public: - diffuse_light(shared_ptr a) : emit(a) {} - diffuse_light(const color& c) : emit(make_shared(c)) {} + diffuse_light(shared_ptr tex) : tex(tex) {} + diffuse_light(const color& emit) : tex(make_shared(emit)) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { @@ -120,28 +122,28 @@ class diffuse_light : public material { } color emitted(double u, double v, const point3& p) const override { - return emit->value(u, v, p); + return tex->value(u, v, p); } private: - shared_ptr emit; + shared_ptr tex; }; class isotropic : public material { public: - isotropic(const color& c) : albedo(make_shared(c)) {} - isotropic(shared_ptr a) : albedo(a) {} + isotropic(const color& albedo) : tex(make_shared(albedo)) {} + isotropic(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { scattered = ray(rec.p, random_unit_vector(), r_in.time()); - attenuation = albedo->value(rec.u, rec.v, rec.p); + attenuation = tex->value(rec.u, rec.v, rec.p); return true; } private: - shared_ptr albedo; + shared_ptr tex; }; diff --git a/src/TheNextWeek/quad.h b/src/TheNextWeek/quad.h index 2b40960e..b18a4dda 100644 --- a/src/TheNextWeek/quad.h +++ b/src/TheNextWeek/quad.h @@ -16,8 +16,8 @@ class quad : public hittable { public: - quad(const point3& _Q, const vec3& _u, const vec3& _v, shared_ptr m) - : Q(_Q), u(_u), v(_v), mat(m) + quad(const point3& Q, const vec3& u, const vec3& v, shared_ptr mat) + : Q(Q), u(u), v(v), mat(mat) { auto n = cross(u, v); normal = unit_vector(n); diff --git a/src/TheNextWeek/sphere.h b/src/TheNextWeek/sphere.h index 8a5ab457..870d3730 100644 --- a/src/TheNextWeek/sphere.h +++ b/src/TheNextWeek/sphere.h @@ -19,24 +19,24 @@ class sphere : public hittable { public: // Stationary Sphere - sphere(const point3& _center, double _radius, shared_ptr _material) - : center1(_center), radius(_radius), mat(_material), is_moving(false) + sphere(const point3& center, double radius, shared_ptr mat) + : center1(center), radius(radius), mat(mat), is_moving(false) { auto rvec = vec3(radius, radius, radius); bbox = aabb(center1 - rvec, center1 + rvec); } // Moving Sphere - sphere(const point3& _center1, const point3& _center2, double _radius, - shared_ptr _material) - : center1(_center1), radius(_radius), mat(_material), is_moving(true) + sphere(const point3& center1, const point3& center2, double radius, + shared_ptr mat) + : center1(center1), radius(radius), mat(mat), is_moving(true) { auto rvec = vec3(radius, radius, radius); - aabb box1(_center1 - rvec, _center1 + rvec); - aabb box2(_center2 - rvec, _center2 + rvec); + aabb box1(center1 - rvec, center1 + rvec); + aabb box2(center2 - rvec, center2 + rvec); bbox = aabb(box1, box2); - center_vec = _center2 - _center1; + center_vec = center2 - center1; } bool hit(const ray& r, interval ray_t, hit_record& rec) const override { diff --git a/src/TheNextWeek/texture.h b/src/TheNextWeek/texture.h index e412e735..c4adbf2a 100644 --- a/src/TheNextWeek/texture.h +++ b/src/TheNextWeek/texture.h @@ -27,27 +27,27 @@ class texture { class solid_color : public texture { public: - solid_color(const color& c) : color_value(c) {} + solid_color(const color& albedo) : albedo(albedo) {} solid_color(double red, double green, double blue) : solid_color(color(red,green,blue)) {} color value(double u, double v, const point3& p) const override { - return color_value; + return albedo; } private: - color color_value; + color albedo; }; class checker_texture : public texture { public: - checker_texture(double _scale, shared_ptr _even, shared_ptr _odd) - : inv_scale(1.0 / _scale), even(_even), odd(_odd) {} + checker_texture(double scale, shared_ptr even, shared_ptr odd) + : inv_scale(1.0 / scale), even(even), odd(odd) {} - checker_texture(double _scale, const color& c1, const color& c2) - : inv_scale(1.0 / _scale), + checker_texture(double scale, const color& c1, const color& c2) + : inv_scale(1.0 / scale), even(make_shared(c1)), odd(make_shared(c2)) {} @@ -73,7 +73,7 @@ class noise_texture : public texture { public: noise_texture() {} - noise_texture(double sc) : scale(sc) {} + noise_texture(double scale) : scale(scale) {} color value(double u, double v, const point3& p) const override { return color(.5, .5, .5) * (1 + sin(scale * p.z() + 10 * noise.turb(p, 7))); diff --git a/src/TheRestOfYourLife/aabb.h b/src/TheRestOfYourLife/aabb.h index 8e00774a..daf7317d 100644 --- a/src/TheRestOfYourLife/aabb.h +++ b/src/TheRestOfYourLife/aabb.h @@ -20,8 +20,8 @@ class aabb { aabb() {} // The default AABB is empty, since intervals are empty by default. - aabb(const interval& _x, const interval& _y, const interval& _z) - : x(_x), y(_y), z(_z) + aabb(const interval& x, const interval& y, const interval& z) + : x(x), y(y), z(z) { pad_to_minimums(); } diff --git a/src/TheRestOfYourLife/constant_medium.h b/src/TheRestOfYourLife/constant_medium.h index 4aa2bb22..3ccb09c1 100644 --- a/src/TheRestOfYourLife/constant_medium.h +++ b/src/TheRestOfYourLife/constant_medium.h @@ -20,12 +20,14 @@ class constant_medium : public hittable { public: - constant_medium(shared_ptr b, double d, shared_ptr a) - : boundary(b), neg_inv_density(-1/d), phase_function(make_shared(a)) + constant_medium(shared_ptr boundary, double density, shared_ptr tex) + : boundary(boundary), neg_inv_density(-1/density), + phase_function(make_shared(tex)) {} - constant_medium(shared_ptr b, double d, const color& c) - : boundary(b), neg_inv_density(-1/d), phase_function(make_shared(c)) + constant_medium(shared_ptr boundary, double density, const color& c) + : boundary(boundary), neg_inv_density(-1/density), + phase_function(make_shared(c)) {} bool hit(const ray& r, interval ray_t, hit_record& rec) const override { diff --git a/src/TheRestOfYourLife/hittable.h b/src/TheRestOfYourLife/hittable.h index 8948bdf6..f7df9c32 100644 --- a/src/TheRestOfYourLife/hittable.h +++ b/src/TheRestOfYourLife/hittable.h @@ -59,8 +59,8 @@ class hittable { class translate : public hittable { public: - translate(shared_ptr p, const vec3& displacement) - : object(p), offset(displacement) + translate(shared_ptr object, const vec3& offset) + : object(object), offset(offset) { bbox = object->bounding_box() + offset; } @@ -90,7 +90,7 @@ class translate : public hittable { class rotate_y : public hittable { public: - rotate_y(shared_ptr p, double angle) : object(p) { + rotate_y(shared_ptr object, double angle) : object(object) { auto radians = degrees_to_radians(angle); sin_theta = sin(radians); cos_theta = cos(radians); diff --git a/src/TheRestOfYourLife/interval.h b/src/TheRestOfYourLife/interval.h index a8b849a7..333e954b 100644 --- a/src/TheRestOfYourLife/interval.h +++ b/src/TheRestOfYourLife/interval.h @@ -15,7 +15,7 @@ class interval { interval() : min(+infinity), max(-infinity) {} // Default interval is empty - interval(double _min, double _max) : min(_min), max(_max) {} + interval(double min, double max) : min(min), max(max) {} interval(const interval& a, const interval& b) : min(fmin(a.min, b.min)), max(fmax(a.max, b.max)) {} diff --git a/src/TheRestOfYourLife/material.h b/src/TheRestOfYourLife/material.h index f9999c7d..1f658fc6 100644 --- a/src/TheRestOfYourLife/material.h +++ b/src/TheRestOfYourLife/material.h @@ -49,11 +49,11 @@ class material { class lambertian : public material { public: - lambertian(const color& a) : albedo(make_shared(a)) {} - lambertian(shared_ptr a) : albedo(a) {} + lambertian(const color& albedo) : tex(make_shared(albedo)) {} + lambertian(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const override { - srec.attenuation = albedo->value(rec.u, rec.v, rec.p); + srec.attenuation = tex->value(rec.u, rec.v, rec.p); srec.pdf_ptr = make_shared(rec.normal); srec.skip_pdf = false; return true; @@ -66,13 +66,13 @@ class lambertian : public material { } private: - shared_ptr albedo; + shared_ptr tex; }; class metal : public material { public: - metal(const color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {} + metal(const color& albedo, double fuzz) : albedo(albedo), fuzz(fuzz < 1 ? fuzz : 1) {} bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const override { srec.attenuation = albedo; @@ -93,13 +93,13 @@ class metal : public material { class dielectric : public material { public: - dielectric(double index_of_refraction) : ir(index_of_refraction) {} + dielectric(double ref_index) : ref_index(ref_index) {} bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const override { srec.attenuation = color(1.0, 1.0, 1.0); srec.pdf_ptr = nullptr; srec.skip_pdf = true; - double refraction_ratio = rec.front_face ? (1.0/ir) : ir; + double refraction_ratio = rec.front_face ? (1.0/ref_index) : ref_index; vec3 unit_direction = unit_vector(r_in.direction()); double cos_theta = fmin(dot(-unit_direction, rec.normal), 1.0); @@ -118,7 +118,8 @@ class dielectric : public material { } private: - double ir; // Index of Refraction + double ref_index; // Refractive index in vacuum or air, or the ratio of the material's + // refractive index over the refractive index of the enclosing media static double reflectance(double cosine, double ref_idx) { // Use Schlick's approximation for reflectance. @@ -131,28 +132,28 @@ class dielectric : public material { class diffuse_light : public material { public: - diffuse_light(shared_ptr a) : emit(a) {} - diffuse_light(const color& c) : emit(make_shared(c)) {} + diffuse_light(shared_ptr tex) : tex(tex) {} + diffuse_light(const color& emit) : tex(make_shared(emit)) {} color emitted(const ray& r_in, const hit_record& rec, double u, double v, const point3& p) const override { if (!rec.front_face) return color(0,0,0); - return emit->value(u, v, p); + return tex->value(u, v, p); } private: - shared_ptr emit; + shared_ptr tex; }; class isotropic : public material { public: - isotropic(const color& c) : albedo(make_shared(c)) {} - isotropic(shared_ptr a) : albedo(a) {} + isotropic(const color& albedo) : tex(make_shared(albedo)) {} + isotropic(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const override { - srec.attenuation = albedo->value(rec.u, rec.v, rec.p); + srec.attenuation = tex->value(rec.u, rec.v, rec.p); srec.pdf_ptr = make_shared(); srec.skip_pdf = false; return true; @@ -164,7 +165,7 @@ class isotropic : public material { } private: - shared_ptr albedo; + shared_ptr tex; }; diff --git a/src/TheRestOfYourLife/pdf.h b/src/TheRestOfYourLife/pdf.h index 4ee1475f..7ba6e397 100644 --- a/src/TheRestOfYourLife/pdf.h +++ b/src/TheRestOfYourLife/pdf.h @@ -60,8 +60,8 @@ class sphere_pdf : public pdf { class hittable_pdf : public pdf { public: - hittable_pdf(const hittable& _objects, const point3& _origin) - : objects(_objects), origin(_origin) + hittable_pdf(const hittable& objects, const point3& origin) + : objects(objects), origin(origin) {} double value(const vec3& direction) const override { diff --git a/src/TheRestOfYourLife/quad.h b/src/TheRestOfYourLife/quad.h index 91e1bd04..e04d45a7 100644 --- a/src/TheRestOfYourLife/quad.h +++ b/src/TheRestOfYourLife/quad.h @@ -16,8 +16,8 @@ class quad : public hittable { public: - quad(const point3& _Q, const vec3& _u, const vec3& _v, shared_ptr m) - : Q(_Q), u(_u), v(_v), mat(m) + quad(const point3& Q, const vec3& u, const vec3& v, shared_ptr mat) + : Q(Q), u(u), v(v), mat(mat) { auto n = cross(u, v); normal = unit_vector(n); diff --git a/src/TheRestOfYourLife/sphere.h b/src/TheRestOfYourLife/sphere.h index ebb77c40..35500722 100644 --- a/src/TheRestOfYourLife/sphere.h +++ b/src/TheRestOfYourLife/sphere.h @@ -20,24 +20,24 @@ class sphere : public hittable { public: // Stationary Sphere - sphere(const point3& _center, double _radius, shared_ptr _material) - : center1(_center), radius(_radius), mat(_material), is_moving(false) + sphere(const point3& center, double radius, shared_ptr mat) + : center1(center), radius(radius), mat(mat), is_moving(false) { auto rvec = vec3(radius, radius, radius); bbox = aabb(center1 - rvec, center1 + rvec); } // Moving Sphere - sphere(const point3& _center1, const point3& _center2, double _radius, - shared_ptr _material) - : center1(_center1), radius(_radius), mat(_material), is_moving(true) + sphere(const point3& center1, const point3& center2, double radius, + shared_ptr mat) + : center1(center1), radius(radius), mat(mat), is_moving(true) { auto rvec = vec3(radius, radius, radius); - aabb box1(_center1 - rvec, _center1 + rvec); - aabb box2(_center2 - rvec, _center2 + rvec); + aabb box1(center1 - rvec, center1 + rvec); + aabb box2(center2 - rvec, center2 + rvec); bbox = aabb(box1, box2); - center_vec = _center2 - _center1; + center_vec = center2 - center1; } bool hit(const ray& r, interval ray_t, hit_record& rec) const override { diff --git a/src/TheRestOfYourLife/texture.h b/src/TheRestOfYourLife/texture.h index e412e735..c4adbf2a 100644 --- a/src/TheRestOfYourLife/texture.h +++ b/src/TheRestOfYourLife/texture.h @@ -27,27 +27,27 @@ class texture { class solid_color : public texture { public: - solid_color(const color& c) : color_value(c) {} + solid_color(const color& albedo) : albedo(albedo) {} solid_color(double red, double green, double blue) : solid_color(color(red,green,blue)) {} color value(double u, double v, const point3& p) const override { - return color_value; + return albedo; } private: - color color_value; + color albedo; }; class checker_texture : public texture { public: - checker_texture(double _scale, shared_ptr _even, shared_ptr _odd) - : inv_scale(1.0 / _scale), even(_even), odd(_odd) {} + checker_texture(double scale, shared_ptr even, shared_ptr odd) + : inv_scale(1.0 / scale), even(even), odd(odd) {} - checker_texture(double _scale, const color& c1, const color& c2) - : inv_scale(1.0 / _scale), + checker_texture(double scale, const color& c1, const color& c2) + : inv_scale(1.0 / scale), even(make_shared(c1)), odd(make_shared(c2)) {} @@ -73,7 +73,7 @@ class noise_texture : public texture { public: noise_texture() {} - noise_texture(double sc) : scale(sc) {} + noise_texture(double scale) : scale(scale) {} color value(double u, double v, const point3& p) const override { return color(.5, .5, .5) * (1 + sin(scale * p.z() + 10 * noise.turb(p, 7))); diff --git a/v3/src/TheRestOfYourLife/material.h b/v3/src/TheRestOfYourLife/material.h index d86d69d3..ea1df49c 100644 --- a/v3/src/TheRestOfYourLife/material.h +++ b/v3/src/TheRestOfYourLife/material.h @@ -139,7 +139,7 @@ class dielectric : public material { class diffuse_light : public material { public: diffuse_light(shared_ptr a) : emit(a) {} - diffuse_light(color c) : emit(make_shared(c)) {} + diffuse_light(color emit) : emit(make_shared(emit)) {} virtual color emitted( const ray& r_in, const hit_record& rec, double u, double v, const point3& p