Exemple #1
0
        public static void DarkRoom(Camera camera, Scene scene)
        {
            //(2.138888, 1.241551, -0.6152115) Target: (1.217189, 1.035707, -0.2864288)
            //camera.Update(new Vector3(3.61508f, 2.465492f, 8.432084f), new Vector3(3.699683f, 2.259647f, 7.457158f));
            //camera.Update(new Vector3(2.138888f, 1.241551f, -0.6152115f), new Vector3(1.217189f, 1.035707f, -0.2864288f));
            //(5.049499, 1.474878, 0.4852568) Target: (4.071804, 1.269033, 0.526975)
            camera.Update(new Vector3(5.049499f, 1.474878f, 0.4852568f), new Vector3(4.071804f, 1.269033f, 0.526975f));

            scene.Skybox = new SingleColorSkybox(Color4.Black);

            //light
            scene.Add(CreateLight(new Vector3(2.5f,5,-5f), Color4.White, 10, 10));

            //floor
            scene.Add(new Plane(
                Vector3.UnitY,
                0,
                new Material(MaterialType.Diffuse) { Texture = new Checkerboard(5, Color4.DarkGray, Color4.White) }
            ));

            var mat = new Material(MaterialType.Diffuse);
            scene.Add(Sphere.CreateOnGround(new Vector3(0,0.5f,0), 0.5f, mat.WithColor(Color4.Red)));
            scene.Add(Sphere.CreateOnGround(new Vector3(0,-0.5f,0), 0.5f, mat));
            scene.Add(new SphereLight(new Vector3(1,1,1), 0.5f, Color4.White, 2));
            scene.Add(Sphere.CreateOnGround(new Vector3(1, -0.5f, 1), 0.5f, mat));
            scene.Add(Sphere.CreateOnGround(new Vector3(2,0.5f,2), 0.5f, mat.WithColor(Color4.Blue)));
            scene.Add(Sphere.CreateOnGround(new Vector3(2, -0.5f, 2), 0.5f, mat));
            //_scene.Add(new Sphere(new Vector3(0, 0.2f, 0), 0.2f, mat.WithColor(Color4.Red)));
            //_scene.Add(new Sphere(new Vector3(1, 0.4f, 0), 0.4f, mat.WithColor(Color4.Blue)));
            //_scene.Add(new Sphere(new Vector3(2.5f, 0.8f, 0), 0.8f, mat.WithColor(Color4.Green)));
            //_scene.Add(new Sphere(new Vector3(5, 1.6f, 0), 1.6f, mat.WithColor(Color4.Yellow)));
        }
Exemple #2
0
 public Intersection(Intersectable intersectsWith, Ray ray, Vector3 surfaceNormal, Vector3 location, float distance, Material material)
 {
     IntersectsWith = intersectsWith;
     Ray = ray;
     SurfaceNormal = surfaceNormal;
     Location = location;
     Distance = distance;
     Material = material;
 }
Exemple #3
0
 public Sphere(Vector3 center, float radius, Material material)
     : base(material)
 {
     Center = center;
     Radius = radius;
     _rad2 = radius*radius;
     var radVector = new Vector3(radius);
     BoundingBox = new BoundingBox(center - radVector, center + radVector);
 }
Exemple #4
0
        public Triangle(Vector3 p1, Vector3 p2, Vector3 p3, Material material)
            : base(material)
        {
            _p1 = p1;

            //vectors of triangle edges
            _e1 = Vector3.Subtract(p2, _p1);
            _e2 = Vector3.Subtract(p3, _p1);
            Normal = Vector3.Cross(_e1, _e2).Normalized();
            BoundingBox = BoundingBox.FromVectors(p1, p2, p3);
        }
Exemple #5
0
        public TriangleMesh(Vector3 position, Obj obj, Material material)
        {
            Position = position;
            _obj = obj;

            foreach (var face in _obj.FaceList)
            {
                var p1 = ToVector3(_obj.VertexList[face.VertexIndexList[0] - 1]) + Position;
                var p2 = ToVector3(_obj.VertexList[face.VertexIndexList[1] - 1]) + Position;
                var p3 = ToVector3(_obj.VertexList[face.VertexIndexList[2] - 1]) + Position;
                Boundables.Add(new Triangle(p1, p2, p3, material));
            }
        }
Exemple #6
0
        public Quad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Material material)
        {
            P1 = p1;
            P2 = p2;
            P3 = p3;
            P4 = p4;
            Material = material;
            var t1 = new Triangle(p1, p2, p4, material);
            var t2 = new Triangle(p2, p3, p4, material);
            Normal = t1.Normal;
            Boundables.Add(t1);
            Boundables.Add(t2);

            Width = p2 - p1;
            Depth = p4 - p1;
        }
Exemple #7
0
 public Intersection(Intersectable intersectsWith, Ray ray, Vector3 surfaceNormal, Vector3 location,
     float distance, Material material, bool insidePrimitive)
     : this(intersectsWith, ray, surfaceNormal, location, distance, material)
 {
     InsidePrimitive = insidePrimitive;
 }
Exemple #8
0
 public static Sphere CreateOnGround(Vector3 groundPoint, float radius, Material material)
 {
     var center = groundPoint + new Vector3(0, radius, 0);
     return new Sphere(center, radius, material);
 }
Exemple #9
0
 public DebugSphere(PointLight light, float radius, Material material)
     : base(light.Position, radius, material)
 {
     _light = light;
 }
Exemple #10
0
        public static void PathTracerBoxCool(Camera camera, Scene scene)
        {
            AddSkybox(scene);
            AddFloor(scene);
            camera.Update(new Vector3(-0.01214953f, 1.140012f, 2.391021f), new Vector3(-0.007645808f, 1.0049f, 1.400201f));

            var debugLight = new PointLight(new Vector3(0, 1f, -0.5f), Color4.White, 2);
            scene.Add(debugLight);
            scene.Add(new PointLight(new Vector3(5,5,5), Color4.White, 30));

            scene.Add(new SphereLight(new Vector3(0f, 1.95f, 0), 0.4f, Color4.White, 4));

            //var lightWidth = 1.75f;
            //var hw = lightWidth/2;
            //scene.Add(new SurfaceLight(
            //    new Vector3(-hw, 1.99f, hw),
            //    new Vector3(-hw, 1.99f,-hw),
            //    new Vector3(hw, 1.99f, -hw),
            //    new Vector3(hw, 1.99f,  hw),
            //    Color4.White
            //    ));

            var diffuse = new Material(MaterialType.Diffuse);
            scene.Add(Sphere.CreateOnGround(new Vector3(-0.5f, 0, 0), 0.3f, diffuse.WithColor(Color4.Green)));
            //_scene.Add(Sphere.CreateOnGround(new Vector3(-0.5f, 0, 0), 0.3f, new Material(MaterialType.Light)));
            scene.Add(Sphere.CreateOnGround(new Vector3(0.4f, 0, 0.6f), 0.2f, Material.Metal));
            scene.Add(Sphere.CreateOnGround(new Vector3(0.5f, 0, -0.4f), 0.4f, Material.Glass));

            var wallMat = new Material(MaterialType.Diffuse) { Color = new Color3(0.7f, 0.7f, 0.7f)};
            //top
            scene.Add(new Quad(
                new Vector3(-1, 2, -4),
                new Vector3(1, 2, -4),
                new Vector3(1, 2,  4),
                new Vector3(-1, 2, 4),
                 wallMat
                ));

            //bottom
            scene.Add(new Quad(
                new Vector3(-1, 0, -4),
                new Vector3(-1, 0, 4),
                new Vector3(1, 0, 4),
                new Vector3(1, 0, -4),
                 wallMat
                ));

            //left
            scene.Add(new Quad(
                new Vector3(-1, 0, -4),
                new Vector3(-1, 2, -4),
                new Vector3(-1, 2, 4),
                new Vector3(-1, 0, 4),
                 wallMat
                ));

            //right
            scene.Add(new Quad(
                new Vector3(1, 0, -4),
                new Vector3(1, 0, 4),
                new Vector3(1, 2, 4),
                new Vector3(1, 2, -4),
                 wallMat
                ));

            //back
            //scene.Add(new Quad(
            //    new Vector3(-1, 0, -1),
            //    new Vector3(1, 0, -1),
            //    new Vector3(1, 2, -1),
            //    new Vector3(-1, 2, -1),
            //     wallMat
            //    ));

            ////front
            //scene.Add(new Quad(
            //    new Vector3(-1, 0, 4),
            //    new Vector3(-1, 2, 4),
            //    new Vector3(1, 2, 4),
            //    new Vector3(1, 0, 4),
            //     wallMat
            //    ));
        }
Exemple #11
0
 public Plane(Vector3 normal, float height, Material material)
     : base(material)
 {
     _normal = normal;
     _height = height;
 }
Exemple #12
0
 protected Primitive(Material material)
 {
     Material = material;
 }
Exemple #13
0
 public static TriangleMesh Load(string path, Vector3 position, Material material)
 {
     var obj = new Obj();
     obj.LoadObj(path);
     return new TriangleMesh(position,  obj, material);
 }