Schlick reflection
This commit is contained in:
parent
7ca342d5a4
commit
0a0080ce80
1 changed files with 22 additions and 13 deletions
|
@ -67,7 +67,8 @@ public:
|
|||
bool cannot_refract = refraction_ratio * sin_theta > 1.0;
|
||||
vec3 direction;
|
||||
|
||||
if (cannot_refract)
|
||||
if (cannot_refract ||
|
||||
reflectance(cos_theta, refraction_ratio) > random_double())
|
||||
direction = reflect(unit_direction, rec.normal);
|
||||
else
|
||||
direction = refract(unit_direction, rec.normal, refraction_ratio);
|
||||
|
@ -78,6 +79,14 @@ public:
|
|||
|
||||
public:
|
||||
double ir;
|
||||
|
||||
private:
|
||||
static double reflectance(double cosine, double ref_idx) {
|
||||
// Use Schlick's approximation for reflectance
|
||||
auto r0 = (1 - ref_idx) / (1 + ref_idx);
|
||||
r0 = r0 * r0;
|
||||
return r0 + (1 - r0) * pow((1 - cosine), 5);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MATERIAL_H_
|
||||
|
|
Loading…
Reference in a new issue