public void HelperClassForProducingSphereWithGlassyMaterial_ShouldExist() { var s = new GlassSphere(); Assert.Equal(Matrix.Identity, s.Transform, MatrixComparer); Assert.Equal(1.0, s.Material.Transparency); Assert.Equal(1.5, s.Material.RefractiveIndex); }
public void SchlickApproximationWithSmallAngleAndN2GreaterThanN1_ShouldBeSignificant() { var shape = new GlassSphere(); var r = new Ray(new Point(0, 0.99, -2), new Vector(0, 0, 1)); var xs = new List <Intersection> { new Intersection(1.8589, shape) }; var comps = xs[0].PrepareComputations(r, xs); Assert.Equal(0.48873, comps.Schlick(), 4); }
public void SchlickApproximationWithPerpendicularViewingAngle_ShouldBeSmall() { var shape = new GlassSphere(); var r = new Ray(new Point(0, 0, 0), new Vector(0, 1, 0)); var xs = new List <Intersection> { new Intersection(-1, shape), new Intersection(1, shape) }; var comps = xs[1].PrepareComputations(r, xs); Assert.Equal(0.04, comps.Schlick(), 2); }
public void SchlickApproximationUnderTotalInternalReflection_ShouldReturn1() { var shape = new GlassSphere(); var r = new Ray(new Point(0, 0, Math.Sqrt(2) / 2), new Vector(0, 1, 0)); var xs = new List <Intersection> { new Intersection(-Math.Sqrt(2) / 2, shape), new Intersection(Math.Sqrt(2) / 2, shape) }; var comps = xs[1].PrepareComputations(r, xs); Assert.Equal(1.0, comps.Schlick()); }
public void WhenCalculatingUnderPoint_ShouldOffsetBelowTheSurface() { var r = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1)); var shape = new GlassSphere(); shape.Transform = Transformation.Translation(0, 0, 1); var i = new Intersection(5, shape); var xs = new List <Intersection> { i }; var comps = i.PrepareComputations(r, xs); Assert.True(comps.UnderPoint.z > EPSILON / 2); Assert.True(comps.Point.z < comps.UnderPoint.z); }
public void FindingN1AndN2AtVariousIntersections_ShouldWork() { var A = new GlassSphere(); A.Transform = Transformation.Scaling(2, 2, 2); A.Material.RefractiveIndex = 1.5; var B = new GlassSphere(); B.Transform = Transformation.Translation(0, 0, -0.25); B.Material.RefractiveIndex = 2.0; var C = new GlassSphere(); C.Transform = Transformation.Translation(0, 0, 0.25); C.Material.RefractiveIndex = 2.5; var r = new Ray(new Point(0, 0, -4), new Vector(0, 0, 1)); var x0 = new Intersection(2, A); var x1 = new Intersection(2.75, B); var x2 = new Intersection(3.25, C); var x3 = new Intersection(4.75, B); var x4 = new Intersection(5.25, C); var x5 = new Intersection(6, A); var xs = new List <Intersection> { x0, x1, x2, x3, x4, x5 }; var comps0 = x0.PrepareComputations(r, xs); var comps1 = x1.PrepareComputations(r, xs); var comps2 = x2.PrepareComputations(r, xs); var comps3 = x3.PrepareComputations(r, xs); var comps4 = x4.PrepareComputations(r, xs); var comps5 = x5.PrepareComputations(r, xs); Assert.Equal(1.0, comps0.n1); Assert.Equal(1.5, comps0.n2); Assert.Equal(1.5, comps1.n1); Assert.Equal(2.0, comps1.n2); Assert.Equal(2.0, comps2.n1); Assert.Equal(2.5, comps2.n2); Assert.Equal(2.5, comps3.n1); Assert.Equal(2.5, comps3.n2); Assert.Equal(2.5, comps4.n1); Assert.Equal(1.5, comps4.n2); Assert.Equal(1.5, comps5.n1); Assert.Equal(1.0, comps5.n2); }