aboutsummaryrefslogtreecommitdiff
path: root/material.go
diff options
context:
space:
mode:
Diffstat (limited to 'material.go')
-rw-r--r--material.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/material.go b/material.go
index 62a0467..6b3a528 100644
--- a/material.go
+++ b/material.go
@@ -65,7 +65,7 @@ func (d Dielectric) Scatter(r Ray, hit HitRecord) Ray {
unit_dir := r.Direction.Unit();
cos_theta := maths.Min(unit_dir.Neg().Dot(hit.N), 1.0);
- sin_theta := maths.Sqrt(1.0 - maths.Pow(cos_theta, 2));
+ sin_theta := maths.Sqrt(1.0 - cos_theta * cos_theta);
cannot_refract := ri * sin_theta > 1.0;
@@ -80,7 +80,10 @@ func (d Dielectric) Scatter(r Ray, hit HitRecord) Ray {
}
func schlick_reflect(cos_theta float64, ri float64) bool {
- r0 := maths.Pow((1 - ri) / (1 + ri), 2);
- approx := r0 + (1 - r0) * maths.Pow(1 - cos_theta, 5);
+ r0 := (1 - ri) / (1 + ri);
+ r0 = r0 * r0;
+ ct5 := 1 - cos_theta;
+ ct5 = ct5 * ct5 * ct5 * ct5 * ct5;
+ approx := r0 + (1 - r0) * ct5;
return approx > Interval{0, 1}.Sample();
}