Example #1
0
        public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing)
        {
            var renderTarget = new Framebuffer(width, height);

            var reflectiveFloor = new ReflectiveMaterial(FloatColor.White, 0.4f, 1, 300, 0.5f);

            var crystalMaterial = new PbrMaterial(FloatColor.White,
                                                  Texture.LoadFrom(@"_Resources/Textures/crystal-green.png").ToInfo(1),
                                                  Texture.LoadFrom(@"_Resources/Textures/crystal-green.png").ToInfo(1),
                                                  Texture.LoadFrom(@"_Resources/Textures/crystal-roughness.png").ToInfo(1),
                                                  Texture.LoadFrom(@"_Resources/Textures/crystal-normals.png").ToInfo(1))
            {
                EmissionFactor     = 1,
                DiffuseCoefficient = 1,
                Specular           = 10,
                SpecularExponent   = 50,
                AmbientPower       = 1
            };

            var reflectiveCrystal  = new ReflectiveMaterial(FloatColor.White, 0.7f, 0.5f, 1000, 0.6f);
            var transparentCrystal = new TransparentMaterial(FloatColor.White, 0.1f, 0, 0.3f, 1.05f, 0.9f);
            var transparentSphere  = new TransparentMaterial(FloatColor.White, 0.1f, 0, 0.3f, 1.05f, 0.9f);

            var crystal  = Model.LoadFromFile("_Resources/Models/crystal.obj", crystalMaterial, 1.5f);
            var crystal2 = Model.LoadFromFile("_Resources/Models/crystal.obj", reflectiveCrystal, 1.5f,
                                              Vector3.Left * 1.5f, Vector3.Forward, 45);
            var crystal3 = Model.LoadFromFile("_Resources/Models/crystal.obj", transparentCrystal, 1.5f,
                                              Vector3.Right * 1.5f, Vector3.Forward, -45);

            renderTarget.Clear(color);

            var objects = new List <IHittable>
            {
                new Plane(new Vector3(-2, 0, 0), new Vector3(1, 0, 0), reflectiveFloor),
                new Plane(new Vector3(2, 0, 0), new Vector3(-1, 0, 0), reflectiveFloor),
                new Plane(new Vector3(5, -2f, 0), new Vector3(0, 1, 0), reflectiveFloor),
                new Plane(new Vector3(5, 2f, 0), new Vector3(0, -1, 0), reflectiveFloor),
                new Plane(new Vector3(0, 2, 6), new Vector3(0, 0, -1), reflectiveFloor),
                new Plane(new Vector3(0, 2, -8), new Vector3(0, 0, 1), reflectiveFloor),
                new Sphere(Vector3.Zero, 1, transparentSphere)
            };

            objects.Add(crystal);
            objects.Add(crystal2);
            objects.Add(crystal3);

            var sampler = new Sampler(new RegularGenerator(), new SquareDistributor(), 25, 1);
            var camera  = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -5), Vector3.Forward, Vector3.Up)
            {
                Sampler  = sampler,
                MaxDepth = 5,
            };

            Scene = new Scene(objects, camera,
                              new List <Light>
            {
                new PointLight
                {
                    Position  = new Vector3(0, 0, 5),
                    Color     = FloatColor.White,
                    Intensity = 1
                }
            },
                              FloatColor.Black);
        }
Example #2
0
        public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing)
        {
            var renderTarget = new Framebuffer(width, height);

            renderTarget.Clear(color);
            var objects = new List <IHittable>();

            var reflectiveMaterial  = new ReflectiveMaterial(FloatColor.White, 0.4f, 1, 300, 1f);
            var transparentMaterial = new TransparentMaterial(FloatColor.White, 0.1f, 0, 1, 3, 1);
            var reflectiveFloor     = new ReflectiveMaterial(FloatColor.White, 0.4f, 1, 300, 0.5f);

            var circuitryMaterial = new PbrMaterial(FloatColor.White,
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-albedo.png").ToInfo(3),
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-emission.png").ToInfo(3),
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-smoothness.png").ToInfo(3),
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-normals.png").ToInfo(3))
            {
                EmissionFactor     = 2,
                DiffuseCoefficient = 1,
                Specular           = 10,
                SpecularExponent   = 50,
                AmbientPower       = 1
            };

            var sphereTextureMaterial = new PbrMaterial(FloatColor.White,
                                                        Texture.LoadFrom(@"_Resources/Textures/lava-albedo-smoothness-green.png").ToInfo(3),
                                                        Texture.LoadFrom(@"_Resources/Textures/lava-emission-green.png").ToInfo(3),
                                                        Texture.LoadFrom(@"_Resources/Textures/lava-albedo-smoothness.png").ToInfo(3),
                                                        Texture.LoadFrom(@"_Resources/Textures/lava-normals.png").ToInfo(3))
            {
                EmissionFactor     = 4,
                DiffuseCoefficient = 1,
                Specular           = 10,
                SpecularExponent   = 50,
                AmbientPower       = 1
            };

            var reflectiveSphere  = new Sphere(new Vector3(-0.5f, -1.5f, 3), 0.5f, reflectiveMaterial);
            var transparentSphere = new Sphere(new Vector3(0.5f, -1.5f, 3), 0.5f, transparentMaterial);
            var textureSphere     = new Sphere(new Vector3(-1.5f, -1.5f, 3), 0.5f, sphereTextureMaterial);
            var specialSphere     = new Sphere(new Vector3(1.5f, -1.5f, 3), 0.5f, circuitryMaterial);

            var reflectiveSphere1  = new Sphere(new Vector3(1.5f, -0.5f, 3), 0.5f, reflectiveMaterial);
            var transparentSphere1 = new Sphere(new Vector3(-1.5f, -0.5f, 3), 0.5f, transparentMaterial);
            var textureSphere1     = new Sphere(new Vector3(-0.5f, -0.5f, 3), 0.5f, sphereTextureMaterial);
            var specialSphere1     = new Sphere(new Vector3(0.5f, -0.5f, 3), 0.5f, circuitryMaterial);

            var reflectiveSphere2  = new Sphere(new Vector3(-1.5f, 0.5f, 3), 0.5f, reflectiveMaterial);
            var transparentSphere2 = new Sphere(new Vector3(1.5f, 0.5f, 3), 0.5f, transparentMaterial);
            var textureSphere2     = new Sphere(new Vector3(0.5f, 0.5f, 3), 0.5f, sphereTextureMaterial);
            var specialSphere2     = new Sphere(new Vector3(-0.5f, 0.5f, 3), 0.5f, circuitryMaterial);

            var reflectiveSphere3  = new Sphere(new Vector3(0.5f, 1.5f, 3), 0.5f, reflectiveMaterial);
            var transparentSphere3 = new Sphere(new Vector3(-0.5f, 1.5f, 3), 0.5f, transparentMaterial);
            var textureSphere3     = new Sphere(new Vector3(1.5f, 1.5f, 3), 0.5f, sphereTextureMaterial);
            var specialSphere3     = new Sphere(new Vector3(-1.5f, 1.5f, 3), 0.5f, circuitryMaterial);

            objects.Add(new Plane(new Vector3(-2, 0, 0), new Vector3(1, 0, 0), reflectiveFloor));
            objects.Add(new Plane(new Vector3(2, 0, 0), new Vector3(-1, 0, 0), reflectiveFloor));
            objects.Add(new Plane(new Vector3(5, -2f, 0), new Vector3(0, 1, 0), reflectiveFloor));
            objects.Add(new Plane(new Vector3(5, 2f, 0), new Vector3(0, -1, 0), reflectiveFloor));
            objects.Add(new Plane(new Vector3(0, 2, 6), new Vector3(0, 0, -1), reflectiveFloor));
            objects.Add(new Plane(new Vector3(0, 2, -8), new Vector3(0, 0, 1), reflectiveFloor));
            objects.Add(reflectiveSphere);
            objects.Add(transparentSphere);
            objects.Add(textureSphere);
            objects.Add(specialSphere);
            objects.Add(reflectiveSphere1);
            objects.Add(transparentSphere1);
            objects.Add(textureSphere1);
            objects.Add(specialSphere1);
            objects.Add(reflectiveSphere2);
            objects.Add(transparentSphere2);
            objects.Add(textureSphere2);
            objects.Add(specialSphere2);
            objects.Add(reflectiveSphere3);
            objects.Add(transparentSphere3);
            objects.Add(textureSphere3);
            objects.Add(specialSphere3);

            var sampler = new Sampler(new JitteredGenerator(0), new SquareDistributor(), 16, 32);
            var camera  = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -5), Vector3.Forward, Vector3.Up)
            {
                Sampler  = sampler,
                MaxDepth = 4
            };

            Scene = new Scene(objects, camera,
                              new List <Light>
            {
                new PointLight
                {
                    Position = new Vector3(0, 0, 3),
                    Color    = FloatColor.White,
                    Sampler  = sampler
                },
                new PointLight
                {
                    Position = new Vector3(0, 0, 0),
                    Color    = FloatColor.White / 2,
                    Sampler  = sampler
                },
                // new PointLight
                // {
                //     Position = new Vector3(1, 1f, 0),
                //     Color = FloatColor.Purple,
                // //    Sampler = sampler
                // },
                // new PointLight
                // {
                //     Position = new Vector3(-2, -1f, 0),
                //     Color = FloatColor.Green,
                // //    Sampler = sampler
                // },
            },
                              FloatColor.Black);
        }
Example #3
0
        public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing)
        {
            var renderTarget = new Framebuffer(width, height);

            renderTarget.Clear(color);
            var objects = new List <IHittable>();

            var sierpinsky = Texture.CreateFrom(FractalGenerator.SierpinskyCarpet(100, 100, Color.White, Color.Black))
                             .ToInfo();
            var reflectiveMaterial  = new ReflectiveMaterial(FloatColor.White, 0.4f, 1, 300, 1f, sierpinsky);
            var transparentMaterial = new TransparentMaterial(FloatColor.White, 0.1f, 0, 0.3f, 1.05f, 0.9f);

            var circuitryMaterial = new PbrMaterial(FloatColor.White,
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-albedo.png").ToInfo(0.25f),
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-emission.png").ToInfo(0.25f),
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-smoothness.png").ToInfo(0.25f),
                                                    Texture.LoadFrom(@"_Resources/Textures/circuitry-normals.png").ToInfo(0.25f))
            {
                EmissionFactor     = 2,
                DiffuseCoefficient = 1,
                Specular           = 10,
                SpecularExponent   = 50,
                AmbientPower       = 1
            };

            var greenLavaMaterial = new PbrMaterial(FloatColor.White,
                                                    Texture.LoadFrom(@"_Resources/Textures/lava-albedo-smoothness-green.png").ToInfo(3),
                                                    Texture.LoadFrom(@"_Resources/Textures/lava-emission-green.png").ToInfo(3),
                                                    Texture.LoadFrom(@"_Resources/Textures/lava-albedo-smoothness.png").ToInfo(3),
                                                    Texture.LoadFrom(@"_Resources/Textures/lava-normals.png").ToInfo(3))
            {
                EmissionFactor     = 4,
                DiffuseCoefficient = 1,
                Specular           = 10,
                SpecularExponent   = 50,
                AmbientPower       = 1
            };

            var reflectiveSphere  = new Sphere(new Vector3(2f, -1f, 4), 1f, reflectiveMaterial);
            var transparentSphere = new Sphere(new Vector3(0f, -1f, 2), 1f, transparentMaterial);
            var textureSphere     = new Sphere(new Vector3(-1.5f, -1.5f, 3), 0.5f, greenLavaMaterial);

            objects.Add(reflectiveSphere);
            objects.Add(transparentSphere);
            objects.Add(textureSphere);
            objects.Add(new Plane(new Vector3(5, -2f, 0), new Vector3(0, 1, 0), circuitryMaterial));

            var sampler = new Sampler(new JitteredGenerator(0), new SquareDistributor(), 16, 32);
            var camera  = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -5), Vector3.Forward, Vector3.Up)
            {
                Sampler  = sampler,
                MaxDepth = 6,
            };

            Scene = new Scene(objects, camera,
                              new List <Light>
            {
                new PointLight
                {
                    Position = new Vector3(1, 1, 0),
                    Color    = FloatColor.White,
                },
                new PointLight
                {
                    Position = new Vector3(-1, 1, 0),
                    Color    = FloatColor.White,
                },
                new PointLight
                {
                    Position  = new Vector3(-2, 2, 15),
                    Color     = FloatColor.White,
                    Intensity = 1
                },
                new PointLight
                {
                    Position = new Vector3(1, 1f, 0),
                    Color    = FloatColor.Green,
                },
                new PointLight
                {
                    Position = new Vector3(-2, -1f, 0),
                    Color    = FloatColor.Red,
                },
            },
                              FloatColor.Black);
        }
Example #4
0
        public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing)
        {
            var renderTarget = new Framebuffer(width, height);

            renderTarget.Clear(color);
            var objects = new List <IHittable>();

            var reflectiveMaterial  = new ReflectiveMaterial(FloatColor.White, 0.4f, 1, 300, 1f);
            var transparentMaterial = new TransparentMaterial(FloatColor.White, 0.1f, 0, 1, 3, 1);
            var whiteWallMaterial   = new PhongMaterial(FloatColor.White, 1, 0, 50, 1);

            var reflectiveSphere  = new Sphere(new Vector3(-1.25f, 0, 3), 1f, reflectiveMaterial);
            var transparentSphere = new Sphere(new Vector3(1.25f, 0, -1), 1f, transparentMaterial);

            objects.Add(new Plane(new Vector3(-4, 0, 0), new Vector3(1, 0, 0), whiteWallMaterial));
            objects.Add(new Plane(new Vector3(4, 0, 0), new Vector3(-1, 0, 0), whiteWallMaterial));
            objects.Add(new Plane(new Vector3(5, -2, 0), new Vector3(0, 1, 0), whiteWallMaterial));
            objects.Add(new Plane(new Vector3(5, 2, 0), new Vector3(0, -1, 0), whiteWallMaterial));
            objects.Add(new Plane(new Vector3(0, 2, 6), new Vector3(0, 0, -1), whiteWallMaterial));
            objects.Add(new Plane(new Vector3(0, 2, -8), new Vector3(0, 0, 1), whiteWallMaterial));
            objects.Add(reflectiveSphere);
            objects.Add(transparentSphere);

            var crystalMaterial = new PbrMaterial(FloatColor.White,
                                                  Texture.LoadFrom(@"_Resources/Textures/crystal.png").ToInfo(),
                                                  Texture.LoadFrom(@"_Resources/Textures/crystal.png").ToInfo(),
                                                  null,
                                                  Texture.LoadFrom(@"_Resources/Textures/crystal-normals.png").ToInfo());
            var crystal = Model.LoadFromFile("_Resources/Models/crystal.obj", crystalMaterial, 2f,
                                             Vector3.Zero);


            objects.Add(crystal);


            var sampler = new Sampler(new JitteredGenerator(0), new SquareDistributor(), 64, 64);
            var camera  = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -6), Vector3.Forward, Vector3.Up)
            {
                Sampler  = sampler,
                MaxDepth = 4
            };

            Scene = new Scene(objects, camera,
                              new List <Light>
            {
                new PointLight
                {
                    Position = new Vector3(-1, 0f, 0),
                    Color    = FloatColor.Blue,
                    Sampler  = sampler
                },
                new PointLight
                {
                    Position = new Vector3(1, 1f, 0),
                    Color    = FloatColor.Purple,
                    Sampler  = sampler
                },
                new PointLight
                {
                    Position = new Vector3(-2, -1f, 0),
                    Color    = FloatColor.Green,
                    Sampler  = sampler
                },
            }, FloatColor.Black);
        }