From 9e67a8260fee8f8a423a3131bcf13db3b9de6922 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Thu, 27 Jun 2024 15:43:38 +0100 Subject: maths.Pow turned out to be seriously terrible --- material.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'material.go') 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(); } -- cgit v1.2.1