public void ShouldFindN1AndN2AtIntersection(int index, float n1, float n2)
        {
            var a = Sphere.CreateGlass();

            a.Transform = CreateScale(2, 2, 2);
            a.Material.RefractiveIndex = 1.5f;

            var b = Sphere.CreateGlass();

            b.Transform = CreateTranslation(0, 0, -0.25f);
            b.Material.RefractiveIndex = 2f;

            var c = Sphere.CreateGlass();

            c.Transform = CreateTranslation(0, 0, 0.25f);
            c.Material.RefractiveIndex = 2.5f;

            var r  = new Ray(CreatePoint(0, 0, -4f), CreateVector(0, 0, 1));
            var xs = new List <Intersection>
            {
                new Intersection(2, a),
                new Intersection(2.75f, b),
                new Intersection(3.25f, c),
                new Intersection(4.75f, b),
                new Intersection(5.25f, c),
                new Intersection(6, a),
            };

            var comps = Computations.Prepare(xs[index], r, xs);

            comps.N1.Should().BeApproximately(n1, Tolerance);
            comps.N2.Should().BeApproximately(n2, Tolerance);
        }
Exemplo n.º 2
0
        public void ShouldCreateGlassSphere()
        {
            var s = Sphere.CreateGlass();

            AssertActualEqualToExpected(s.Transform, Identity);
            s.Material.Transparency.Should().Be(1);
            s.Material.RefractiveIndex.Should().BeApproximately(1.5f, Tolerance);
        }
        public void ShouldComputeSchlickApproximationWithSmallAngleAndN2GreaterThanN1()
        {
            var shape       = Sphere.CreateGlass();
            var r           = new Ray(CreatePoint(0, .99f, -2), CreateVector(0, 0, 1));
            var xs          = Intersection.CreateList((1.8589f, shape));
            var comps       = Computations.Prepare(xs[0], r, xs);
            var reflectance = comps.GetSchlickReflectance();

            reflectance.Should().BeApproximately(0.48873f, Tolerance);
        }
        public void ShouldComputeSchlickApproximationWithPerpendicularViewingAngle()
        {
            var shape       = Sphere.CreateGlass();
            var r           = new Ray(CreatePoint(0, 0, 0), CreateVector(0, 1, 0));
            var xs          = Intersection.CreateList((-1, shape), (1, shape));
            var comps       = Computations.Prepare(xs[1], r, xs);
            var reflectance = comps.GetSchlickReflectance();

            reflectance.Should().BeApproximately(0.04f, Tolerance);
        }
        public void ShouldComputeSchlickApproximationUnderTotalInternalReflection()
        {
            var shape       = Sphere.CreateGlass();
            var r           = new Ray(CreatePoint(0, 0, Sqrt(2) / 2), CreateVector(0, 1, 0));
            var xs          = Intersection.CreateList((-Sqrt(2) / 2, shape), (Sqrt(2) / 2, shape));
            var comps       = Computations.Prepare(xs[1], r, xs);
            var reflectance = comps.GetSchlickReflectance();

            reflectance.Should().BeApproximately(1, Tolerance);
        }
        public void ShouldComputeUnderPointBelowTheSurface()
        {
            var r     = new Ray(CreatePoint(0, 0, -5f), CreateVector(0, 0, 1));
            var shape = Sphere.CreateGlass();

            shape.Transform = CreateTranslation(0, 0, 1);
            var i  = new Intersection(5, shape);
            var xs = new List <Intersection> {
                i
            };
            var comps = Computations.Prepare(i, r, xs);

            comps.UnderPoint.Z.Should().BeGreaterThan(Tolerance / 2);
            comps.Point.Z.Should().BeLessThan(comps.UnderPoint.Z);
        }
        public static World CreateTestWorld()
        {
            var floor = new XZPlane("floor")
            {
                Material =
                {
                    Pattern       = new CheckerPattern(VColor.LinearRGB(1, 0.5f,              0.5f), VColor.Red)
                    {
                        Transform = CreateScale(2,                            2, 2) * CreateShear(0,1, 0, 0, 0, 0)
                    },
                    Specular   =                                     0,
                    Reflective =                                  0.1f,
                },
            };
            var water = new XZPlane("water")
            {
                Transform = CreateTranslation(0, 0.25f, 0),
                Material  =
                {
                    Color           = VColor.LinearRGB(0, 0, 0.1f),
                    Reflective      =               0.4f,
                    RefractiveIndex =               1.7f,
                    Transparency    =               0.9f,
                }
            };
            var rightWall = new XZPlane("right wall")
            {
                Transform =
                    CreateRotationZ(-MathF.PI / 2) *
                    CreateTranslation(5, 0, 0),
                Material =
                {
                    Pattern  = new RingPattern(VColor.Green, VColor.White),
                    Specular =                            0,
                },
            };
            var leftWall = new XZPlane("left wall")
            {
                Transform =
                    CreateRotationX(MathF.PI / 2) *
                    CreateTranslation(0, 0, 5),
                Material =
                {
                    Pattern  = new StripePattern(VColor.Blue, VColor.LinearRGB(0.5f, 0.5f, 1)),
                    Specular =                             0,
                },
            };
            var middle = new Sphere("middle")
            {
                Transform = CreateTranslation(-0.5f, 1, 0.5f),
                Material  =
                {
                    Pattern         = new GradientPattern(VColor.LinearRGB(0.1f, 1, 0.5f), VColor.SRGB(1, 0.5f, 0))
                    {
                        Transform   =
                            CreateScale(2, 1, 1) *
                            CreateTranslation(1, 0, 0),
                    },
                    Diffuse         =                                      0.7f,
                    Specular        =                                      0.3f,
                    Reflective      =                                     0.05f,
                    Transparency    =                                      0.3f,
                    RefractiveIndex =                                      1.5f,
                }
            };
            var right = Sphere.CreateGlass("right");

            right.Transform = CreateScale(0.5f, 0.5f, 0.5f) *
                              CreateTranslation(1.5f, 0.5f, -0.5f);
            right.Material.Color = VColor.Black;

            var left = new Cone("left")
            {
                Closed    = true,
                Minimum   = -1,
                Maximum   = 1,
                Transform = CreateScale(0.33f, 1, 0.33f) *
                            CreateTranslation(-1.5f, 1, -0.75f),
                Material =
                {
                    Color = VColor.White,
                    //Ambient = 0.1f,
                    //Diffuse = 0.4f,
                    //Specular = 0,
                }
            };

            return(new World
            {
                Objects = { floor, water, rightWall, leftWall, middle, right, left, },
                Lights =
                {
                    new PointLight(CreatePoint(-10, 10, -10), VColor.LinearRGB(0.3f, 0.3f, 0.3f)),
                    new PointLight(CreatePoint(0,   10, -10), VColor.LinearRGB(0.3f, 0.3f, 0.3f)),
                    new PointLight(CreatePoint(3,   10, -10), VColor.LinearRGB(0.3f, 0.3f, 0.3f)),
                },
            });
        }