mirror of
https://github.com/Manoj-HV30/multithreaded-raytracer.git
synced 2026-05-16 19:35:24 +00:00
Refactor scatter method
This commit is contained in:
+3
-4
@@ -23,7 +23,7 @@ class lambertian : public material {
|
|||||||
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
|
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
|
||||||
const override {
|
const override {
|
||||||
auto scatter_direction = rec.normal + random_unit_vector();
|
auto scatter_direction = rec.normal + random_unit_vector();
|
||||||
// Catch degenerate scatter direction
|
|
||||||
if (scatter_direction.near_zero())
|
if (scatter_direction.near_zero())
|
||||||
scatter_direction = rec.normal;
|
scatter_direction = rec.normal;
|
||||||
|
|
||||||
@@ -81,11 +81,10 @@ class dielectric : public material {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Refractive index in vacuum or air, or the ratio of the material's refractive index over
|
|
||||||
// the refractive index of the enclosing media
|
|
||||||
double refraction_index;
|
double refraction_index;
|
||||||
static double reflectance(double cosine, double refraction_index) {
|
static double reflectance(double cosine, double refraction_index) {
|
||||||
// Use Schlick's approximation for reflectance.
|
|
||||||
auto r0 = (1 - refraction_index) / (1 + refraction_index);
|
auto r0 = (1 - refraction_index) / (1 + refraction_index);
|
||||||
r0 = r0*r0;
|
r0 = r0*r0;
|
||||||
return r0 + (1-r0)*std::pow((1 - cosine),5);
|
return r0 + (1-r0)*std::pow((1 - cosine),5);
|
||||||
|
|||||||
Reference in New Issue
Block a user