aboutsummaryrefslogtreecommitdiff
path: root/material.go
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-27 15:43:38 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-27 15:43:38 +0100
commit9e67a8260fee8f8a423a3131bcf13db3b9de6922 (patch)
tree472a4dfccc2d4e1cf8ba72d3eed509f8cced6878 /material.go
parent2211a942161d6509421915996f4351419adb990f (diff)
maths.Pow turned out to be seriously terrible
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();
}