-
Notifications
You must be signed in to change notification settings - Fork 939
Description
The issue is related to the reflectance function in the dielectric class (material.h, line 86).
Schlick’s approximation for Fresnel reflection is given by:
where:
Here, the refractive index transitions from
In the implementation, the variable ri
represents etai_over_etat
, or reflectance(cos_theta, 1 / ri)
rather than reflectance(cos_theta, ri)
. However, because of the squared term in the formula:
the original implementation reflectance(cos_theta, ri)
also produces the correct result.
That said, this implementation might be confusing for beginners (I must admit, I initially misinterpreted it myself XD). Since the book does not explicitly include the Fresnel reflection equation or Schlick’s approximation, it would be helpful to provide a brief introduction beforehand. Alternatively, the implementation could be made clearer by explicitly passing both refractive indices, like this:
// Usage
reflectance(cos_theta_i, ri, 1.0);
// Function
static double reflectance(double cos_theta_i, double eta_i, double eta_t) {
double r0 = (eta_i - eta_t) / (eta_i + eta_t);
r0 *= r0;
return r0 + (1 - r0) * std::pow(1 - cos_theta_i, 5);
}
Also, I think it would be more helpful to briefly introduce the formulas for Fresnel reflection coefficients