Beispiel #1
0
        private static Scene SimpleSphereScene(int width, int height, out Stopwatch stopwatch, out Camera camera)
        {
            stopwatch = Stopwatch.StartNew();

            Sphere[] spheres = new Sphere[]
            {
                new Sphere(new Vector3(0, -100.5f, -1), 100, new LambertianMaterial(new Vector3(.8f, .8f, .8f))),
                new Sphere(new Vector3(2, 0, -1), 0.5f, new LambertianMaterial(new Vector3(0.8f, 0.4f, 0.4f))),
                new Sphere(new Vector3(0, 0, -1), 0.5f, new LambertianMaterial(new Vector3(0.4f, 0.8f, 0.4f))),
                new Sphere(new Vector3(-2, 0, -1), 0.5f, new MetalMaterial(new Vector3(.4f, .4f, .8f), 0)),
                new Sphere(new Vector3(2, 0, 1), 0.5f, new MetalMaterial(new Vector3(.4f, .8f, .4f), 0)),
                new Sphere(new Vector3(0, 0, 1), 0.5f, new MetalMaterial(new Vector3(.4f, .8f, .4f), 0.2f)),
                new Sphere(new Vector3(-2, 0, 1), 0.5f, new MetalMaterial(new Vector3(.4f, .8f, .4f), 0.6f)),
                new Sphere(new Vector3(0.5f, 1.25f, 0.5f), 0.5f, new DielectricMaterial(1.5f)),
                new Sphere(new Vector3(-1.5f, 1.5f, 0f), 0.3f, new LambertianMaterial(new Vector3(.8f, .6f, .2f)))
            };

            Scene scene = new Scene();
            SceneSphereHitSystem sphereHitSystem = scene.GetOrCreateHitSystem <SceneSphereHitSystem>();

            for (int i = 0; i < spheres.Length; i++)
            {
                sphereHitSystem.Add(spheres[i]);
            }

            scene.PrepareForRendering();
            stopwatch.Stop();
            camera = new Camera(new Vector3(0, 2, 3), new Vector3(0, 0, 0), new Vector3(0, 1, 0), 70, (float)width / (float)height, 0.025f, 3f);

            return(scene);
        }
Beispiel #2
0
        private static Scene TeapotScene(int width, int height, out Stopwatch stopwatch, out Camera camera)
        {
            stopwatch = Stopwatch.StartNew();

            Sphere[] spheres = new Sphere[]
            {
                new Sphere(new Vector3(0, -100.5f, -1), 100, new LambertianMaterial(new Vector3(.8f, .8f, .8f))),
                new Sphere(new Vector3(2, 0, -1), 0.5f, new LambertianMaterial(new Vector3(0.8f, 0.4f, 0.4f))),
                new Sphere(new Vector3(0, 0, -1), 0.5f, new LambertianMaterial(new Vector3(0.4f, 0.8f, 0.4f))),
                new Sphere(new Vector3(-2, 0, -1), 0.5f, new MetalMaterial(new Vector3(.4f, .4f, .8f), 0)),
                new Sphere(new Vector3(2, 0, 1), 0.5f, new MetalMaterial(new Vector3(.4f, .8f, .4f), 0)),
                new Sphere(new Vector3(0, 0, 1), 0.5f, new MetalMaterial(new Vector3(.4f, .8f, .4f), 0.2f)),
                new Sphere(new Vector3(-2, 0, 1), 0.5f, new MetalMaterial(new Vector3(.4f, .8f, .4f), 0.6f)),
                new Sphere(new Vector3(0.5f, 1.25f, 0.5f), 0.5f, new DielectricMaterial(1.5f)),
                //new Sphere(new Vector3(-1.5f,1.5f,0f), 0.3f, new LambertianMaterial(new Vector3(.8f, .6f, .2f)))
            };

            Scene                scene             = new Scene();
            TriangleHitSystem    triangleHitSystem = scene.GetOrCreateHitSystem <TriangleHitSystem>();
            SceneSphereHitSystem sphereHitSystem   = scene.GetOrCreateHitSystem <SceneSphereHitSystem>();

            for (int i = 0; i < spheres.Length; i++)
            {
                sphereHitSystem.Add(spheres[i]);
            }

            List <Triangle> triangles = new List <Triangle>();

            WavefrontLoader.Load(File.ReadAllText(@"Resources/Teapot/teapot.obj"), ref triangles);

            var mat = new MetalMaterial(new Vector3(1, .84f, 0), .01f);

            // var mat = new DielectricMaterial(1.5f);
            for (int i = 0; i < triangles.Count; i++)
            {
                var tri = triangles[i];
                tri.p1 *= .01f;                          // Scale down
                tri.p2 *= .01f;                          // Scale down
                tri.p3 *= .01f;                          // Scale down
                tri.p1 += new Vector3(-1.5f, 1.25f, 0f); // Translate
                tri.p2 += new Vector3(-1.5f, 1.25f, 0f); // Translate
                tri.p3 += new Vector3(-1.5f, 1.25f, 0f); // Translate

                tri.material = mat;

                triangleHitSystem.Add(tri);
            }

            // triangleHitSystem.Add(new Triangle(new Vector3(-2, 0, 1), new Vector3(0, 1, 1), new Vector3(2, 0, 1), mat));

            scene.PrepareForRendering();
            stopwatch.Stop();
            camera = new Camera(new Vector3(0, 2, 3), new Vector3(0, 0, 0), new Vector3(0, 1, 0), 70, (float)width / (float)height, 0.025f, 3f);

            return(scene);
        }