Example #1
0
        public void FindingN1AndN2AtVariousIntersections(int index, double n1, double n2)
        {
            var a = new GlassSphere()
            {
                Transform = Transform.Scale(2, 2, 2),
            };

            var b = new GlassSphere()
            {
                Transform = Transform.Translate(0, 0, -0.25),
            };

            var c = new GlassSphere()
            {
                Transform = Transform.Translate(0, 0, 25),
            };

            a.Material.RefractiveIndex = 1.5;
            b.Material.RefractiveIndex = 2.0;
            c.Material.RefractiveIndex = 2.5;

            var r = new Ray(Vector4.CreatePosition(0, 0, -4), Vector4.CreateDirection(0, 0, 1));
            var xs = IntersectionList.Create(
                new Intersection(2, a),
                new Intersection(2.75, b),
                new Intersection(3.25, c),
                new Intersection(4.75, b),
                new Intersection(5.25, c),
                new Intersection(6, a));

            var comps = xs[index].Precompute(r, xs);
            Assert.Equal(n1, comps.N1);
            Assert.Equal(n2, comps.N2);
        }
Example #2
0
        public void HelperForSphereWithGlassyMaterial()
        {
            var s = new GlassSphere();

            Assert.Equal(Matrix4x4.Identity, s.Transform);
            Assert.Equal(1.0, s.Material.Transparency);
            Assert.Equal(1.5, s.Material.RefractiveIndex);
        }
Example #3
0
 public void SchlickApproxWithSmallAngleAndN2GreaterThanN1()
 {
     var shape = new GlassSphere();
     var r = new Ray(Vector4.CreatePosition(0, 0.99, -2), Vector4.CreateDirection(0, 0, 1));
     var xs = IntersectionList.Create(
         new Intersection(1.8589, shape));
     var comps = xs[0].Precompute(r, xs);
     var reflectance = comps.SchlicksApproximation();
     const int prec = 5;
     Assert.Equal(0.48873, reflectance, prec);
 }
Example #4
0
        public void SchlickApproxWithPerpendicularViewingAngle()
        {
            var shape = new GlassSphere();
            var r = new Ray(Vector4.CreatePosition(0, 0, 0), Vector4.CreateDirection(0, 1, 0));
            var xs = IntersectionList.Create(
                new Intersection(-1, shape),
                new Intersection(1, shape));

            var comps = xs[1].Precompute(r, xs);
            var reflectance = comps.SchlicksApproximation();
            const int prec = 8;
            Assert.Equal(0.04, reflectance, prec);
        }
Example #5
0
        public void UnderPointIsOffsetBelowTheSurface()
        {
            var r = new Ray(Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 0, 1));
            var shape = new GlassSphere()
            {
                Transform = Transform.Translate(0, 0, 1),
            };

            var i = new Intersection(5, shape);
            var xs = IntersectionList.Create(i);
            var comps = i.Precompute(r, xs);
            Assert.True(comps.UnderPoint.Z > Intersection.Epsilon / 2);
            Assert.True(comps.Point.Z < comps.UnderPoint.Z);
        }
Example #6
0
 public void SchlickApproxUnderTotalInternalReflection()
 {
     var shape = new GlassSphere();
     var r = new Ray(
         Vector4.CreatePosition(0, 0, Math.Sqrt(2)/2), 
         Vector4.CreateDirection(0, 1, 0));
     
     var xs = IntersectionList.Create(
         new Intersection(-Math.Sqrt(2)/2, shape),
         new Intersection(Math.Sqrt(2)/2, shape));
     
     var comps = xs[1].Precompute(r, xs);
     var reflectance = comps.SchlicksApproximation();
     Assert.Equal(1.0, reflectance);
 }