Ejemplo n.º 1
0
        static void Main(string [] args)
        {
            Scene  scene  = new Scene();
            Sphere sphere = new Sphere(2, new double3(0, 0, 10));

            scene.Objects.Add(sphere);

            EyeBasedRayTracer tracer = new EyeBasedRayTracer();

            tracer.Scene        = scene;
            tracer.ViewportSize = new IntSize(100, 100);
            tracer.Camera       = new Camera();

            tracer.Render();
        }
Ejemplo n.º 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            scene = new Scene();
            scene.AmbientColor = double3.Zero;

            sphere1Center = new double3(-3, 0, 10);
            sphere1       = new Sphere(2, sphere1Center);
            //sphere1.Material = refractiveDispersiveMaterial;
            //sphere1.Material = new DebugMaterial ();
            //sphere1.Material = new MappedMaterial ( Texture2d.Load ( @"C:\media\images\Wallpaper\Текстуры\Minerals\AZURITE2.JPG" ), FilteringType.Nearest );
            //sphere1.Material = new MappedMaterial ( Texture2d.Load ( @"C:\media\images\earth2.png" ), TextureWrap.Clamp );
            sphere1.Material = RefractiveDispersiveMaterial.Diamond();
            //sphere1.Material = new RefractiveDispersiveMaterial ( RefractionIndex.Water ( Light.RedWavelength ),
            //    RefractionIndex.Water ( Light.GreenWavelength ), RefractionIndex.Water ( Light.BlueWavelength ), 0.9 );
            //sphere1.Material = new RefractiveDispersiveMaterial ( new RefractionIndex ( 1.1 ),
            //    new RefractionIndex ( 1.5 ), new RefractionIndex ( 2 ) );
            //sphere2 = new Sphere ( 2, new double3 ( 2, 2, 12 ) );
            //sphere2.Material = reflectiveMaterial;
            scene.Objects.Add(sphere1);
            //scene.Objects.Add ( sphere2 );
            //scene.Objects.Add ( sphere3 );

            // Lens test
            Sphere backSphere = new Sphere(2, new double3(-3, 0, 15));

            backSphere.Material = reflectiveMaterial;

            CsgObject convexConcaveLens = new CsgObject(CsgOp.Subtract,
                                                        new Sphere(2, new double3(0, 0, 7)),
                                                        new Sphere(6.5, new double3(0, 0, 12))
                                                        );

            convexConcaveLens.Material = new RefractiveMaterial(1, 1.7);

            CsgObject concaveConvexLens = new CsgObject(CsgOp.Subtract,
                                                        new Sphere(2, new double3(0, 0, 7)),
                                                        new Sphere(6.5, new double3(0, 0, 2))
                                                        );

            concaveConvexLens.Material = new RefractiveMaterial(1, 1.7);

            //scene.Objects.Add ( backSphere );
            //scene.Objects.Add ( convexConcaveLens );
            //scene.Objects.Add ( concaveConvexLens );

            // Csg Subtraction test
            //sphere1 = new Sphere ( 2, sphere1Center );
            //sphere2 = new Sphere ( 2, sphere1Center + double3.UnitX * 2 );
            //Sphere sphere3 = new Sphere ( 2, sphere1Center - double3.UnitZ * 3 );
            //CsgObject csgObj = new CsgObject ( CsgOp.Subtract, sphere1, sphere2, sphere3 );
            //csgObj.Material = new PhongEnvironmentMaterial ( Colors.Orange.ToDouble3 () );
            //scene.Objects.Add ( csgObj );

            // Csg Intersection test
            //sphere1 = new Sphere ( 2, sphere1Center );
            //sphere2 = new Sphere ( 2, sphere1Center + double3.UnitX * 1 );
            //Sphere sphere3 = new Sphere ( 2, sphere1Center + double3.UnitY * 2 );
            //CsgObject csgObj = new CsgObject ( CsgOp.Intersect, sphere1, sphere2, sphere3 );
            //csgObj.Material = new PhongEnvironmentMaterial ( Colors.Orange.ToDouble3 () );
            //scene.Objects.Add ( csgObj );

            // Csg Subtraction and Intersection test
            //sphere1 = new Sphere ( 1.5, sphere1Center - double3.UnitX * 0.75 );
            //sphere2 = new Sphere ( 1.5, sphere1Center + double3.UnitX * 0.75 );
            //CsgObject csgObjIsec = new CsgObject ( CsgOp.Intersect, sphere1, sphere2 );
            ////csgObjIsec.Material = new PhongEnvironmentMaterial ( Colors.Orange.ToDouble3 () );
            ////scene.Objects.Add ( csgObjIsec );
            //Sphere sphere3 = new Sphere ( 2, sphere1Center + double3.UnitZ );
            //CsgObject csgObjSub = new CsgObject ( CsgOp.Subtract, sphere3, csgObjIsec );
            //csgObjSub.Material = new PhongEnvironmentMaterial ( Colors.Orange.ToDouble3 () );
            //scene.Objects.Add ( csgObjSub );

            // Csg Union test
            //sphere1 = new Sphere ( 2, sphere1Center );
            //sphere2 = new Sphere ( 2, sphere1Center + double3.UnitX * 2 );
            //CsgObject csgObjUnion = new CsgObject ( CsgOp.Union, sphere1, sphere2 );
            //csgObjUnion.Material = new PhongEnvironmentMaterial ( Colors.Violet.ToDouble3 () );
            //scene.Objects.Add ( csgObjUnion );

            // Csg Subtract Unions test
            //sphere1 = new Sphere ( 2, sphere1Center );
            //sphere2 = new Sphere ( 2, sphere1Center + double3.UnitX * 2 );
            //CsgObject csgObjUnion1 = new CsgObject ( CsgOp.Union, sphere1, sphere2 );
            //Sphere sphere3 = new Sphere ( 2, sphere1Center + double3.UnitY * 1 - double3.UnitZ );
            //Sphere sphere4 = new Sphere ( 2, sphere1Center + double3.UnitX * 2 + double3.UnitY * 1 - double3.UnitZ );
            //CsgObject csgObjUnion2 = new CsgObject ( CsgOp.Union, sphere3, sphere4 );
            //CsgObject csgObjSub = new CsgObject ( CsgOp.Subtract, csgObjUnion1, csgObjUnion2 );
            //csgObjSub.Material = new PhongEnvironmentMaterial ( Colors.Violet.ToDouble3 () );
            //scene.Objects.Add ( csgObjSub );

            floor = new PlanarSurface(new double3(0, -2, 0), double3.UnitY);
            //floor = new PlanarSurface ( new double3 ( 0, -2, 0 ), new double3 ( 0.2, 1, -0.3 ).Normalized );
            floor.Material = new DebugMaterial();
            //floor.Material = new MappedMaterial ( Texture2d.Load ( @"C:\media\images\Wallpaper\Текстуры\Architectual\DIRTCHEK.JPG" ), TextureWrap.Repeat );
            floor.Material = new PhongEnvironmentMaterial();
            leftWall       = new PlanarSurface(new double3(-10, 0, 0), double3.UnitX);
            //leftWall.Material = new CheckerMaterial ();
            //leftWall.Material = new PhongEnvironmentMaterial ( new double3 ( 1, 0, 0 ) );
            leftWall.Material = new PhongMaterial(new double3(1, 0, 0));
            rightWall         = new PlanarSurface(new double3(10, 0, 0), -double3.UnitX);
            //rightWall.Material = new PhongEnvironmentMaterial ( new double3 ( 0, 0.27, 1 ) );
            rightWall.Material = new PhongMaterial(new double3(0, 0.27, 1));
            frontWall          = new PlanarSurface(new double3(0, 0, 30), -double3.UnitZ);
            //frontWall.Material = new PhongEnvironmentMaterial ( new double3 ( 0.6, 0.27, 1 ) );
            frontWall.Material = new PhongMaterial(new double3(0.6, 0.27, 1));
            backWall           = new PlanarSurface(new double3(0, 0, -60), double3.UnitZ);
            //backWall.Material = new PhongEnvironmentMaterial ( new double3 ( 0.6, 0.6, 0.27 ) );
            backWall.Material = new PhongMaterial(new double3(0.6, 0.6, 0.27));
            ceiling           = new PlanarSurface(new double3(0, 10, 0), -double3.UnitY);
            //ceiling = new PlanarSurface ( new double3 ( 0, 10, 0 ), new double3 ( 0, -1, 0.02 ).Normalized );
            //ceiling.Material = new CheckerMaterial ();
            //ceiling.Material = new PhongEnvironmentMaterial ( new double3 ( 0.27, 1, 0.27 ) );
            ceiling.Material = new PhongMaterial(new double3(0.27, 1, 0.27));
            scene.Objects.Add(floor);
            scene.Objects.Add(leftWall);
            scene.Objects.Add(rightWall);
            scene.Objects.Add(frontWall);
            scene.Objects.Add(backWall);
            scene.Objects.Add(ceiling);

            spotLight1 = new SpotLight(new double3(-2, 4, 0), new double3(1, 0.7, 0.3), new double3(1, 0.7, 0.3), 5);
            spotLight2 = new SpotLight(new double3(5, 3, 8), new double3(0.3, 0.7, 1), new double3(0.3, 0.7, 1), 5);
            scene.Lights.Add(spotLight1);
            scene.Lights.Add(spotLight2);

            camera      = new Camera(new double3(0, 0, 3));
            camera.Pos += double4.UnitZ * 9;
            //camera.Pos += double4.UnitZ * 5 - double4.UnitX * 8 - double4.UnitY * 1.5;
            //camera.View = new double3 ( -2, 0, 10 ) - camera.Pos;
            camera.View = sphere1Center - camera.Pos;
            //camera.FovY = 140;

            eyeBasedTracer = new EyeBasedRayTracer();
            eyeBasedTracer.InitTraceData = new TraceData(10, 10);
            //eyeBasedTracer.ClearColor = double3.UnitY;
            eyeBasedTracer.Scene        = scene;
            eyeBasedTracer.ViewportSize = new IntSize(400, 300);
            //eyeBasedTracer.ViewportSize = new IntSize ( 1024, 768 );
            //eyeBasedTracer.ViewportSize = new IntSize ( 1920, 1080 );
            eyeBasedTracer.Camera = camera;

            sectionTracer              = new SectionRayTracer();
            sectionTracer.Scene        = scene;
            sectionTracer.ViewportSize = new IntSize(400, 300);
            //sectionTracer.ViewportSize = new IntSize ( 1024, 768 );
            //sectionTracer.ViewportSize = new IntSize ( 1920, 1080 );
            double side = 10;

            sectionTracer.SectionSize = new DoubleSize(side * sectionTracer.ViewportSize.width / sectionTracer.ViewportSize.height, side);
            sectionTracer.Camera      = camera;
            //camera.FovY = 50;
            sectionTracer.NumRaysToDraw = 300;
            //sectionTracer.Orientation = SectionOrientation.Vertical;

            tracer = eyeBasedTracer;
            //tracer = sectionTracer;
            //tracer.MaxDegreeOfParallelism = 1;
            tracer.InitTraceData = new TraceData(30, 30);

            Render();

            timer.Interval = TimeSpan.FromSeconds(2.5);
            timer.Tick    += new EventHandler(timer_Tick);
        }