Dielectric kind of works, glass does not

This commit is contained in:
Patrick Stevens
2021-04-17 23:26:05 +01:00
parent 5c1b634539
commit 48ddcc8548
12 changed files with 328 additions and 55 deletions

View File

@@ -1,8 +1,10 @@
namespace RayTracing.Test
open System
open RayTracing
open NUnit.Framework
open FsCheck
open FsUnitTyped
[<TestFixture>]
module TestSphere =
@@ -37,4 +39,73 @@ module TestSphere =
property
|> Prop.forAll (Arb.fromGen gen)
|> Check.QuickThrowOnFailure
|> Check.QuickThrowOnFailure
[<Test>]
let ``Glass sphere perfectly reflects against the edge`` () =
let rand = Random () |> FloatProducer
let ray = Ray.make (Point.make 0.0 0.0 0.0) (Vector.make 0.0 0.0 1.0 |> Vector.unitise |> Option.get)
let strikePoint = Point.make 0.0 0.0 1.0
let destination =
Sphere.reflection
(SphereStyle.Glass (1.0<albedo>, Colour.Green, 1.5<ior>, rand))
(Point.make 0.0 1.0 1.0)
1.0
1.0
false
{ LightRay.Ray = ray ; Colour = Colour.White }
strikePoint
match destination with
| Continues onward ->
onward.Colour |> shouldEqual Colour.Green
Point.equal (Ray.origin onward.Ray) strikePoint |> shouldEqual true
Vector.equal (Ray.vector onward.Ray |> UnitVector.scale 1.0) (Ray.vector ray |> UnitVector.scale 1.0) |> shouldEqual true
| Absorbs colour ->
failwithf "Absorbed: %+A" colour
[<Test>]
let ``Glass sphere perfectly refracts through the middle`` () =
let rand = Random () |> FloatProducer
let ray = Ray.make (Point.make 0.0 0.0 0.0) (Vector.make 0.0 0.0 1.0 |> Vector.unitise |> Option.get)
let strikePoint = Point.make 0.0 0.0 1.0
let destination =
Sphere.reflection
(SphereStyle.Glass (1.0<albedo>, Colour.Green, 1.5<ior>, rand))
(Point.make 0.0 0.0 2.0)
1.0
1.0
false
{ LightRay.Ray = ray ; Colour = Colour.White }
strikePoint
match destination with
| Continues onward ->
onward.Colour |> shouldEqual Colour.Green
Point.equal (Ray.origin onward.Ray) strikePoint |> shouldEqual true
Vector.equal (Ray.vector onward.Ray |> UnitVector.scale 1.0) (Ray.vector ray |> UnitVector.scale 1.0) |> shouldEqual true
| Absorbs colour ->
failwithf "Absorbed: %+A" colour
[<Test>]
let ``Dielectric sphere refracts when incoming ray `` () =
let rand = Random () |> FloatProducer
let ray = Ray.make (Point.make 0.0 0.0 0.0) (Vector.make 0.0 0.0 1.0 |> Vector.unitise |> Option.get)
let strikePoint = Point.make 0.0 0.0 1.0
let destination =
Sphere.reflection
(SphereStyle.Dielectric (1.0<albedo>, Colour.Green, 1.5<ior>, 1.0<prob>, rand))
(Point.make 0.0 0.0 2.0)
1.0
1.0
false
{ LightRay.Ray = ray ; Colour = Colour.White }
strikePoint
match destination with
| Continues onward ->
onward.Colour |> shouldEqual Colour.Green
Point.equal (Ray.origin onward.Ray) strikePoint |> shouldEqual true
Vector.equal (Ray.vector onward.Ray |> UnitVector.scale 1.0) (Ray.vector ray |> UnitVector.scale 1.0) |> shouldEqual true
| Absorbs colour ->
failwithf "Absorbed: %+A" colour