diff options
| author | Martin Lehoux <martin@lehoux.net> | 2020-04-05 22:46:24 -0700 |
|---|---|---|
| committer | Martin Lehoux <martin@lehoux.net> | 2020-04-05 22:46:24 -0700 |
| commit | 96c21470a2064c07d8060de283812392e87c9150 (patch) | |
| tree | dbf30252f5b629d14856f568ebe7a4e540c543bc /vec3d.go | |
| parent | e93eee4bb96bd2d81e422dc9d453da6138fd6ba2 (diff) | |
feat - Add Glass material
Diffstat (limited to 'vec3d.go')
| -rw-r--r-- | vec3d.go | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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} } |
