Пример #1
0
        public void ShadeHitSchlick()
        {
            var w     = World.Default;
            var floor = new Plane(Translation(0, -1, 0))
            {
                Material = { Transparency = .5f, IOR = 1.5f, Reflectivity = .5f }
            };

            w.Objects.Add(floor);
            var s = new Sphere(Translation(0, -3.5f, -.5f))
            {
                Material =
                {
                    BaseColor = new Color(1, 0, 0),
                    Ambient   = .5f
                }
            };

            w.Objects.Add(s);
            var r     = new Ray(0, 0, -3, 0, -MathF.Sqrt(2f) / 2f, MathF.Sqrt(2f) / 2f);
            var xs    = new Intersection(MathF.Sqrt(2f), floor);
            var comps = IntersectionState.Prepare(ref xs, ref r);
            var color = w.ShadeHit(ref comps, 5);

            Assert.That.VectorsAreEqual(color, new Color(.93391f, .69643f, .69243f), 1e-4f);
        }
 public void Chapter_XIV_b()
 {
     var floor = new PhongMaterial(Util.FromHex("#222831"))
     {
         Reflectivity = .9f, Specular = .5f, Shininess = 300
     };
     var p = new Plane(Translation(0, -.25f, 0))
     {
         Material = floor
     };
        public void Chapter_XI_b()
        {
            var floorMaterial = new PhongMaterial(Color.White)
            {
                IOR          = Constants.GlassIOR,
                Reflectivity = 1f
            };
            var skyMaterial = new PhongMaterial(Color.White)
            {
                Pattern = new RingPattern(Util.FromHex("#0092ca"), Util.FromHex("#00adb5"))
            };
            var sky = new Plane(Translation(0, 5, 0))
            {
                Material = skyMaterial
            };
            var floor = new Plane {
                Material = floorMaterial
            };

            var w = new World
            {
                Objects = new List <Entity> {
                    floor, sky
                }
            };

            for (var i = 0; i < 20; i++)
            {
                var rnd = new Random();
                var x   = (float)rnd.NextDouble();
                var y   = (float)rnd.NextDouble();
                var z   = (float)rnd.NextDouble();
                var col = new Color(x, y, z);
                var mat = new PhongMaterial(col)
                {
                    IOR = Constants.GlassIOR, Transparency = y, Reflectivity = x, Specular = z
                };
                var s = new Sphere(Translation((x * 10f) - 5f, y, z * 10f) * Scale(y))
                {
                    Material = mat
                };
                w.Objects.Add(s);
            }
            var l = PointLight.Default;

            l.Intensity *= 2f;
            w.Lights.Add(l);
            var cam = new Camera(20, 10, MathF.PI / 1.5f)
            {
                Transform = Camera.ViewTransform(Point(0f, 1f, -2f), Point(0f, 1f, 0f), Direction(0f, 1f, 0f))
            };

            cam.Render(w);
        }
Пример #4
0
        public void LimitRecursion()
        {
            var w = World.Default;
            var s = new Plane(Translation(0, -1, 0))
            {
                Material = { Reflectivity = .5f }
            };

            w.Objects.Add(s);
            var r     = new Ray(0, 0, -3, 0, -MathF.Sqrt(2f) / 2f, MathF.Sqrt(2f) / 2f);
            var i     = new Intersection(MathF.Sqrt(2f), s);
            var comps = IntersectionState.Prepare(ref i, ref r);
            var col   = w.ReflectedColor(ref comps, 0);

            Assert.That.VectorsAreEqual(col, Color.Black);
        }
Пример #5
0
        public void ShadeHitWithReflective()
        {
            var w = World.Default;
            var s = new Plane(Translation(0f, -1f, 0f))
            {
                Material = { Reflectivity = .5f }
            };

            w.Objects.Add(s);
            var r     = new Ray(0, 0, -3, 0, -MathF.Sqrt(2f) / 2f, MathF.Sqrt(2f) / 2f);
            var i     = new Intersection(MathF.Sqrt(2f), s);
            var comps = IntersectionState.Prepare(ref i, ref r);
            var col   = w.ShadeHit(ref comps, 5);

            Assert.That.VectorsAreEqual(col, new Color(.87677f, .92436f, .82918f), 1e-3f);
        }
Пример #6
0
        public void ReflectedColorReflectiveMaterial()
        {
            var w = World.Default;
            var s = new Plane(Translation(0, -1, 0))
            {
                Material = { Reflectivity = .5f }
            };

            w.Objects.Add(s);
            var r     = new Ray(0, 0, -3, 0, -MathF.Sqrt(2f) / 2f, MathF.Sqrt(2f) / 2f);
            var i     = new Intersection(MathF.Sqrt(2f), s);
            var comps = IntersectionState.Prepare(ref i, ref r);
            var col   = w.ReflectedColor(ref comps, 1);

            Assert.That.VectorsAreEqual(col, new Color(.19032f, .2379f, .14274f), 1e-3f);
        }
        public void Chapter_X()
        {
            var floorMaterial = PhongMaterial.Default;

            floorMaterial.Pattern  = new CheckerPattern(Util.FromHex("#bd2c00"), Util.FromHex("#222222"), RotationY(MathF.PI / 4f));
            floorMaterial.Specular = 0f;

            var back = PhongMaterial.Default;

            back.Pattern  = new RingPattern(Util.FromHex("#0c3866"), Util.FromHex("#007cc0"));
            back.Specular = 0.5f;
            var sphereMaterial = PhongMaterial.Default;

            sphereMaterial.Pattern = new StripePattern(Util.FromHex("#ffc20e"), Util.FromHex("#ffd54f"))
            {
                Transform = Scale(.1f) * RotationY(MathF.PI / 2f)
            };
            sphereMaterial.Diffuse = 1f;
            var floor = new Plane {
                Material = floorMaterial
            };
            var s = new Sphere(Translation(0f, 0f, 2f))
            {
                Material = sphereMaterial
            };
            var backDrop = new Plane(Translation(0f, 0f, 10f) * RotationX(MathF.PI / 2f))
            {
                Material = back
            };
            var w = new World
            {
                Objects = new List <Entity> {
                    floor, s, backDrop
                },
            };

            w.Lights.Add(PointLight.Default);
            var cam = new Camera(10, 10, MathF.PI / 3f)
            {
                Transform = Camera.ViewTransform(Point(0f, 1f, -2f), Point(0f, 1f, 0f), Direction(0f, 1f, 0f))
            };

            cam.Render(w);
        }
Пример #8
0
        public void AvoidInfiniteLoop()
        {
            var w = new World
            {
                Lights = new List <ILight> {
                    new PointLight(Point(0, 0, 0), Color.White)
                }
            };
            var lower = new Plane(Translation(0, -1, 0))
            {
                Material = { Reflectivity = 1 }
            };
            var upper = new Plane(Translation(0, 1, 0))
            {
                Material = { Reflectivity = 1 }
            };

            w.Objects.AddRange(new[] { lower, upper });
            var r = new Ray(0, 0, 0, 0, 1, 0);

            Assert.AreNotEqual(w.ColorAt(ref r, 100), Color.Black);
        }
        public void Chapter_IX()
        {
            var wallMaterial = new PhongMaterial(new Color(.9f, .9f, .9f))
            {
                Specular = 0f
            };
            var floorMaterial = new PhongMaterial(new Color(.7f, .7f, .8f))
            {
                Specular = 0f
            };
            var left = new Plane(Translation(0f, 0f, 10f) * RotationY(MathF.PI / -4f) * RotationX(MathF.PI / 2f))
            {
                Material = wallMaterial
            };
            var right = new Plane(Translation(0f, 0f, 10f) * RotationY(MathF.PI / 4f) * RotationX(MathF.PI / 2f))
            {
                Material = wallMaterial
            };
            var floor = new Plane(Translation(0f, -7f, 0f))
            {
                Material = floorMaterial
            };
            var mescho = Util.LoadMesitaldehydeAtoms();
            var w      = new World
            {
                Objects = new List <Entity> {
                    floor, left, right
                },
            };

            w.Lights.Add(new PointLight(Point(-7f, 15f, -7f), new Color(1f, 1f, 1.05f)));
            w.Objects.AddRange(mescho);
            var cam = new Camera(10, 10, MathF.PI / 3f)
            {
                Transform = Camera.ViewTransform(Point(1f, .5f, -12f), Point(0f, .5f, 0f), Direction(0f, 1f, 0f))
            };

            cam.Render(w);
        }
        public void Chapter_XI_a()
        {
            var floorMaterial = PhongMaterial.Default;

            floorMaterial.Pattern      = new CheckerPattern(Util.FromHex("#393e46"), Util.FromHex("#222831"), RotationY(MathF.PI / 4f));
            floorMaterial.Specular     = 0f;
            floorMaterial.Reflectivity = 1f;

            var sphereMaterial = PhongMaterial.Default;

            sphereMaterial.Pattern = new StripePattern(Util.FromHex("#7bc74d"), Util.FromHex("#eeeeee"))
            {
                Transform = Scale(.1f) * RotationY(MathF.PI / 2f)
            };
            sphereMaterial.Diffuse = 1f;
            var floor = new Plane {
                Material = floorMaterial
            };
            var s = new Sphere(Translation(0f, 1f, 2f) * RotationY(MathF.PI / 4f))
            {
                Material = sphereMaterial
            };

            var w = new World
            {
                Objects = new List <Entity> {
                    floor, s
                },
            };

            w.Lights.Add(PointLight.Default);
            var cam = new Camera(20, 10, MathF.PI / 2f)
            {
                Transform = Camera.ViewTransform(Point(0f, 1f, -2f), Point(0f, 1f, 0f), Direction(0f, 1f, 0f))
            };

            cam.Render(w);
        }
        public void ChapterXIII_a()
        {
            var w = new World();
            var p = new Plane()
            {
                Material = new PhongMaterial(Util.FromHex("#393e46"))
                {
                    Reflectivity = .1f
                }
            };

            w.Objects.Add(p);
            var boostMat = new PhongMaterial(Util.FromHex("#222831"))
            {
                Specular = 0
            };
            var c1 = new Cone(Translation(0.363811f, 0.47248f, 0) * RotationZ(MathF.PI) * Scale(.202f, .367f, .202f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = boostMat
            };
            var c2 = new Cone(Translation(0f, 0.47248f, -0.386016f) * RotationZ(MathF.PI) * Scale(.202f, .367f, .202f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = boostMat
            };
            var c3 = new Cone(Translation(-0.363811f, 0.47248f, 0) * RotationZ(MathF.PI) * Scale(.202f, .367f, .202f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = boostMat
            };
            var c4 = new Cone(Translation(0f, 0.47248f, 0.386016f) * RotationZ(MathF.PI) * Scale(.202f, .367f, .202f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = boostMat
            };

            w.Objects.Add(c1);
            w.Objects.Add(c2);
            w.Objects.Add(c3);
            w.Objects.Add(c4);

            var baseMat = new PhongMaterial(Color.White)
            {
                Pattern      = new StripePattern(Color.White, Color.Black, Scale(.05f) * RotationZ(MathF.PI / 2f)),
                Reflectivity = .7f
            };
            var cyl = new Cylinder(Translation(0, 4.23516f, 0) * Scale(.596f, 3.782f, .596f))
            {
                Minimum = -1f, Maximum = 0f, IsClosed = true, Material = baseMat
            };
            var con = new Cone(Translation(0f, 4.8f, 0f) * RotationZ(MathF.PI) * Scale(.596f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = baseMat
            };

            w.Objects.Add(cyl);
            w.Objects.Add(con);

            var cyl1 = new Cylinder(Translation(0, 5.15554f, 0) * Scale(.411f, 1.104f, .411f))
            {
                Minimum = -1f, Maximum = 0f, IsClosed = true, Material = baseMat
            };
            var con1 = new Cone(Translation(0f, 5.55f, 0f) * RotationZ(MathF.PI) * Scale(.411f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = baseMat
            };

            w.Objects.Add(cyl1);
            w.Objects.Add(con1);

            var cyl2 = new Cylinder(Translation(0, 5.7f, 0) * Scale(.211f, .345f, .211f))
            {
                Minimum = -1f, Maximum = 0f, IsClosed = true, Material = baseMat
            };
            var con2 = new Cone(Translation(0f, 5.9f, 0f) * RotationZ(MathF.PI) * Scale(.211f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = baseMat
            };

            w.Objects.Add(cyl2);
            w.Objects.Add(con2);

            var cyl3 = new Cylinder(Translation(0, 6f, 0) * Scale(.092f, .151f, .092f))
            {
                Minimum = -1f, Maximum = 0f, IsClosed = true, Material = baseMat
            };
            var con3 = new Cone(Translation(0f, 6.1f, 0f) * RotationZ(MathF.PI) * Scale(.092f))
            {
                Minimum = 0, Maximum = 1, IsClosed = true, Material = baseMat
            };

            w.Objects.Add(cyl3);
            w.Objects.Add(con3);
            var topMat = new PhongMaterial(Color.White);
            var cyl4   = new Cylinder(Translation(0, 7f, 0) * Scale(.04f, 3f, .04f))
            {
                Minimum = -1f, Maximum = 0f, IsClosed = true, Material = topMat
            };

            w.Objects.Add(cyl4);

            var cube = new Cube(Translation(-5, 1, -2))
            {
                Material = new PhongMaterial(Color.White)
                {
                    Transparency = 1f, IOR = Constants.GlassIOR, Reflectivity = 0f
                }
            };
            var s = new Sphere(Translation(-5, .5f, -2) * Scale(.5f))
            {
                Material = new PhongMaterial(Color.Red)
                {
                    Reflectivity = 1
                }
            };
            var s2 = new Sphere(Translation(5, 1.5f, 2) * Scale(1.5f))
            {
                Material = new PhongMaterial(Color.Red)
                {
                    Reflectivity = 1
                }
            };
            var cube2 = new Cube(Translation(7, .7f, -2) * Scale(.7f))
            {
                Material = new PhongMaterial(Color.White)
                {
                    Transparency = 1f, IOR = Constants.GlassIOR, Reflectivity = 0f
                }
            };
            var s3 = new Sphere(Translation(5, 1, -2))
            {
                Material = new PhongMaterial(Color.Blue)
                {
                    Reflectivity = 1
                }
            };
            var s4 = new Sphere(Translation(-8, 1, 3))
            {
                Material = new PhongMaterial(Color.Green)
                {
                    Reflectivity = 1
                }
            };

            w.Objects.Add(cube);
            w.Objects.Add(cube2);
            w.Objects.Add(s);
            w.Objects.Add(s2);
            w.Objects.Add(s3);
            w.Objects.Add(s4);
            var l = new PointLight(Point(1.4122f, 10.242f, -10f), Color.White);

            w.Lights.Add(l);
            var cam = new Camera(10, 10, 50 * MathF.PI / 180)
            {
                Transform = Camera.ViewTransform(Point(15.548f, 5f, 0f), Point(0, 1, 0), Vector4.UnitY)
            };

            cam.Render(w);
        }