aboutsummaryrefslogtreecommitdiff
path: root/vec3d.go
diff options
context:
space:
mode:
authorMartin Lehoux <martin@lehoux.net>2020-04-05 22:46:24 -0700
committerMartin Lehoux <martin@lehoux.net>2020-04-05 22:46:24 -0700
commit96c21470a2064c07d8060de283812392e87c9150 (patch)
treedbf30252f5b629d14856f568ebe7a4e540c543bc /vec3d.go
parente93eee4bb96bd2d81e422dc9d453da6138fd6ba2 (diff)
feat - Add Glass material
Diffstat (limited to 'vec3d.go')
-rw-r--r--vec3d.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/vec3d.go b/vec3d.go
index 9e4ced0..5b2a691 100644
--- a/vec3d.go
+++ b/vec3d.go
@@ -29,6 +29,13 @@ func (vec Vec3D) Reflect(normal Vec3D) Vec3D {
return SubVec3D(vec, ScalarProduct(2*DotProduct(vec, normal), normal))
}
+func Refract(vecI Vec3D, normal Vec3D, etaI float64, etaT float64) Vec3D {
+ cosTheta := FMin(DotProduct(vecI.Invert(), normal), 1.0)
+ vecTPar := ScalarProduct(etaI/etaT, AddVec3D(vecI, ScalarProduct(cosTheta, normal)))
+ vecTPer := ScalarProduct(-math.Sqrt(1.0-DotProduct(vecTPar, vecTPar)), normal)
+ return AddVec3D(vecTPar, vecTPer)
+}
+
func AddVec3D(vec1 Vec3D, vec2 Vec3D) Vec3D {
return Vec3D{vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z}
}