mirror of
https://github.com/Smaug123/ray-tracing-fsharp
synced 2025-10-12 15:28:40 +00:00
Dielectric kind of works, glass does not
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user