mirror of
https://github.com/MorizzG/ray-tracer.git
synced 2025-12-06 04:22:42 +00:00
fixed reflectance in Dielectric
This commit is contained in:
parent
3b92603141
commit
d49e7d0300
1 changed files with 6 additions and 5 deletions
|
|
@ -86,17 +86,18 @@ class Dielectric : public Material {
|
|||
|
||||
Vec3 out_dir;
|
||||
|
||||
// Schlick approximation
|
||||
constexpr auto reflectance = [](f64 cos, f64 eta) {
|
||||
auto r0 = (1 - eta) / (1 + eta);
|
||||
r0 = r0 * r0;
|
||||
return r0 * (1 - r0) * std::pow(1 - cos, 5);
|
||||
auto r = (1 - eta) / (1 + eta);
|
||||
f64 r2 = r * r;
|
||||
return r2 + (1 - r2) * std::pow(1 - cos, 5);
|
||||
};
|
||||
|
||||
if (eta * sin_theta > 1.0 || reflectance(cos_theta, eta) > rand.GenUniform()) {
|
||||
// can't refract, must reflect or Schlick approximation
|
||||
// reflect
|
||||
out_dir = in.direction().reflect(hit_record.normal);
|
||||
} else {
|
||||
// reflect
|
||||
// refract
|
||||
out_dir = in.direction().refract(hit_record.normal, eta);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue