Ejemplo n.º 1
0
        public void TestCullerPlaceInTree()
        {
            var           game   = new DX11Game();
            Vector3       radius = new Vector3(100, 1000, 100);
            FrustumCuller culler = new FrustumCuller(new BoundingBox(-radius, radius), 5);


            var visualizer = new QuadTreeVisualizer();

            List <TestCullObject> cullObjects = new List <TestCullObject>();


            TestCullObject obj;

            obj = new TestCullObject(new Vector3(5, 2, 5), 2);
            cullObjects.Add(obj);

            obj = new TestCullObject(new Vector3(-20, 2, -20), 15);
            cullObjects.Add(obj);

            obj = new TestCullObject(new Vector3(100, 2, -20), 4);
            cullObjects.Add(obj);

            obj = new TestCullObject(new Vector3(-50, 9, 24), 20);
            cullObjects.Add(obj);

            for (int i = 0; i < cullObjects.Count; i++)
            {
                culler.AddCullable(cullObjects[i]);
            }

            game.GameLoopEvent +=
                delegate
            {
                for (int i = 0; i < cullObjects.Count; i++)
                {
                    game.LineManager3D.AddBox(cullObjects[i].BoundingBox, Color.Red.dx());
                }
                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Green.dx();

                    return(node.Cullables.Count == 0);
                });

                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Orange.dx();

                    return(node.Cullables.Count > 0);
                });
            };



            game.Run();
        }
Ejemplo n.º 2
0
        public void TestCullerVisibility()
        {
            var           game   = new DX11Game();
            Vector3       radius = new Vector3(100, 1000, 100);
            FrustumCuller culler = new FrustumCuller(new BoundingBox(-radius, radius), 6);



            QuadTreeVisualizer visualizer = new QuadTreeVisualizer();

            List <TestCullObject> cullObjects = new List <TestCullObject>();


            TestCullObject obj;


            for (int i = 0; i < cullObjects.Count; i++)
            {
                culler.AddCullable(cullObjects[i]);
            }



            SpectaterCamera cullCam = new SpectaterCamera(10f, 80);

            cullCam.Positie         = new Vector3(8, 10, 8);
            cullCam.EnableUserInput = false;

            bool rotate = true;

            int selectedNode = -1;

            var view = culler.CreateView();


            game.GameLoopEvent +=
                delegate
            {
                view.UpdateVisibility(cullCam.ViewProjection);
                if (rotate)
                {
                    cullCam.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f);
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPadPlus))
                {
                    selectedNode++;
                }
                if (game.Keyboard.IsKeyPressed(Key.NumberPadMinus))
                {
                    selectedNode--;
                }

                if (game.Keyboard.IsKeyPressed(Key.Return))
                {
                    int count = -1;
                    visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                       delegate(FrustumCuller.CullNode node, out Color4 col)
                    {
                        col = Color.Red.dx();
                        count++;
                        if (count == selectedNode)
                        {
                            node.Tag = "SELECTED!";
                        }
                        return(count == selectedNode);
                    });
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPad0))
                {
                    rotate = !rotate;
                }



                game.LineManager3D.AddViewFrustum(new global::DirectX11.BoundingFrustum(cullCam.ViewProjection), Color.Black.dx());
                for (int i = 0; i < cullObjects.Count; i++)
                {
                    game.LineManager3D.AddBox(cullObjects[i].BoundingBox, Color.Red.dx());
                }
                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Green.dx();

                    return(!view.IsNodeVisible(node));
                });

                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Orange.dx();

                    return(view.IsNodeVisible(node));
                });

                cullCam.Update(game.Elapsed, game.Keyboard, game.Mouse);

                /*int count = -1;
                 * visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                 * delegate(Culler.CullNode node, out Color col)
                 * {
                 *  col = Color.Red;
                 *  count++;
                 *  return count == selectedNode;
                 * });*/
            };



            game.Run();
        }
Ejemplo n.º 3
0
        public void TestCullerObjects()
        {
            var game = new DX11Game();

            game.InitDirectX();
            Vector3       radius = new Vector3(100, 1000, 100);
            FrustumCuller culler = new FrustumCuller(new BoundingBox(-radius, radius), 6);

            var mesh = RenderingTestsHelper.CreateSimpleTestMesh();

            var texturePool = new TexturePool(game);

            var gBuffer = new GBuffer(game.Device, 800, 600);

            var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool);
            var final    = new CombineFinalRenderer(game, gBuffer);



            DeferredMeshElement middle = null;

            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 50; j++)
                {
                    var el = renderer.AddMesh(mesh);
                    el.WorldMatrix = Matrix.Translation(MathHelper.Right * i * 2 + Vector3.UnitZ * j * 2);

                    if (i > 20 && i < 30 && j > 20 && j < 30)
                    {
                        el.Delete();
                    }
                    else
                    {
                        culler.AddCullable(el);
                    }
                }
            }

            QuadTreeVisualizer visualizer = new QuadTreeVisualizer();

            List <TestCullObject> cullObjects = new List <TestCullObject>();



            SpectaterCamera cullCam = new SpectaterCamera(10f, 80);

            cullCam.Positie         = new Vector3(8, 10, 8);
            cullCam.EnableUserInput = false;

            bool rotate = true;

            int selectedNode = -1;

            var view = culler.CreateView();


            game.GameLoopEvent +=
                delegate
            {
                view.UpdateVisibility(cullCam.ViewProjection);
                var visibleCullables = view.GetVisibleCullables();

                if (rotate)
                {
                    cullCam.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f);
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPadPlus))
                {
                    selectedNode++;
                }
                if (game.Keyboard.IsKeyPressed(Key.NumberPadMinus))
                {
                    selectedNode--;
                }

                if (game.Keyboard.IsKeyPressed(Key.Return))
                {
                    int count = -1;
                    visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                       delegate(FrustumCuller.CullNode node, out Color4 col)
                    {
                        col = Color.Red.dx();
                        count++;
                        if (count == selectedNode)
                        {
                            node.Tag = "SELECTED!";
                        }
                        return(count == selectedNode);
                    });
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPad0))
                {
                    rotate = !rotate;
                }



                gBuffer.Clear();
                gBuffer.SetTargetsToOutputMerger();
                renderer.Draw();

                game.Device.ImmediateContext.ClearState();
                game.SetBackbuffer();

                final.DrawCombined();


                game.LineManager3D.AddViewFrustum(new BoundingFrustum(cullCam.ViewProjection), Color.White.dx());
                for (int i = 0; i < visibleCullables.Count; i++)
                {
                    game.LineManager3D.AddBox(visibleCullables[i].BoundingBox, Color.Red.dx());
                }
                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Green.dx();

                    return(!view.IsNodeVisible(node));
                });

                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Orange.dx();

                    return(view.IsNodeVisible(node));
                });

                cullCam.Update(game.Elapsed, game.Keyboard, game.Mouse);


                /*int count = -1;
                 * visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                 * delegate(Culler.CullNode node, out Color col)
                 * {
                 *  col = Color.Red;
                 *  count++;
                 *  return count == selectedNode;
                 * });*/
            };



            game.Run();
        }
Ejemplo n.º 4
0
        public void TestPointLightDownViewFrustumVisibility()
        {
            var game = new DX11Game();

            game.InitDirectX();
            Vector3       radius = new Vector3(100, 1000, 100);
            FrustumCuller culler = new FrustumCuller(new BoundingBox(-radius, radius), 6);



            QuadTreeVisualizer visualizer = new QuadTreeVisualizer();

            List <TestCullObject> cullObjects = new List <TestCullObject>();


            TestCullObject obj;


            for (int i = 0; i < cullObjects.Count; i++)
            {
                culler.AddCullable(cullObjects[i]);
            }



            Matrix viewProjection = Matrix.Identity;

            var pos = game.SpectaterCamera.CameraPosition;

            bool rotate = true;

            int selectedNode = -1;

            var view = culler.CreateView();


            game.GameLoopEvent +=
                delegate
            {
                if (game.Keyboard.IsKeyDown(Key.C))
                {
                    pos = game.SpectaterCamera.CameraPosition;
                }

                viewProjection = PointLightRenderer.CreateShadowMapView(pos, 3) *
                                 PointLightRenderer.CreateShadowMapProjection(10);

                view.UpdateVisibility(viewProjection);


                if (game.Keyboard.IsKeyPressed(Key.NumberPadPlus))
                {
                    selectedNode++;
                }
                if (game.Keyboard.IsKeyPressed(Key.NumberPadMinus))
                {
                    selectedNode--;
                }



                game.LineManager3D.AddViewFrustum(new BoundingFrustum(viewProjection), Color.Black.dx());
                for (int i = 0; i < cullObjects.Count; i++)
                {
                    game.LineManager3D.AddBox(cullObjects[i].BoundingBox, Color.Red.dx());
                }


                if (game.Keyboard.IsKeyDown(Key.Return))
                {
                    int count = -1;
                    visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                       delegate(FrustumCuller.CullNode node, out Color4 col)
                    {
                        col = Color.Green.dx();

                        count++;
                        if (count == selectedNode)
                        {
                            col = Color.Red.dx();

                            node.Tag = "SELECTED!";
                        }
                        return(count == selectedNode);
                    });
                }
                else
                {
                    visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                       delegate(FrustumCuller.CullNode node, out Color4 col)
                    {
                        if (view.IsNodeVisible(node))
                        {
                            col = Color.Orange.dx();
                            return(true);
                        }
                        col = Color.Green.dx();
                        return(false);
                    });
                }

                /*int count = -1;
                 * visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                 * delegate(Culler.CullNode node, out Color col)
                 * {
                 *  col = Color.Red;
                 *  count++;
                 *  return count == selectedNode;
                 * });*/
            };



            game.Run();
        }
Ejemplo n.º 5
0
        public void TestDeferredRendererCity()
        {
            var game = new DX11Game();

            game.InitDirectX();
            SlimDX.Configuration.EnableObjectTracking = false;

            var renderer = new DeferredRenderer(game);

            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());


            var importer = new ObjImporter();

            importer.AddMaterialFileStream("Town001.mtl", new FileStream("../../bin/GameData/Core/Town/OBJ03/Town001.mtl", FileMode.Open));
            importer.ImportObjFile("../../bin/GameData/Core/Town/OBJ03/Town001.obj");

            var meshes = c.CreateMeshesFromObjects(importer);

            for (int index = 0; index < meshes.Count; index++)
            {
                var ramMesh = meshes[index];
                var el      = renderer.CreateMeshElement(ramMesh);
            }
            var directional = renderer.CreateDirectionalLight();

            directional.ShadowsEnabled = true;
            var point = renderer.CreatePointLight();

            point.LightRadius   *= 2;
            point.ShadowsEnabled = true;
            var spot = renderer.CreateSpotLight();

            spot.LightRadius   *= 2;
            spot.ShadowsEnabled = true;

            var visualizer = new QuadTreeVisualizer();

            var  otherCam = new SpectaterCamera(1, 10000);
            var  camState = false;
            int  state    = 0;
            bool rotate   = false;

            game.GameLoopEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Key.D1))
                {
                    state = 0;
                }
                if (game.Keyboard.IsKeyPressed(Key.D2))
                {
                    state = 1;
                }
                if (game.Keyboard.IsKeyPressed(Key.D3))
                {
                    state = 2;
                }
                if (game.Keyboard.IsKeyPressed(Key.D4))
                {
                    state = 3;
                }

                if (game.Keyboard.IsKeyPressed(Key.C))
                {
                    camState = !camState;
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPad0))
                {
                    rotate = !rotate;
                }

                if (rotate)
                {
                    game.SpectaterCamera.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f);
                }

                switch (state)
                {
                case 0:
                    break;

                case 1:
                    directional.LightDirection = game.SpectaterCamera.CameraDirection;
                    break;

                case 2:
                    point.LightPosition = game.SpectaterCamera.CameraPosition;

                    break;

                case 3:
                    spot.LightPosition = game.SpectaterCamera.CameraPosition;
                    spot.SpotDirection = game.SpectaterCamera.CameraDirection;
                    break;
                }

                if (camState)
                {
                    game.Camera = game.SpectaterCamera;
                    renderer.DEBUG_SeperateCullCamera = null;
                }
                else
                {
                    game.Camera = otherCam;
                    renderer.DEBUG_SeperateCullCamera = game.SpectaterCamera;
                }
                game.SpectaterCamera.EnableUserInput = camState;
                otherCam.EnableUserInput             = !camState;
                otherCam.Update(game.Elapsed, game.Keyboard, game.Mouse);


                renderer.Draw();


                if (false)
                {
                    //renderer.DEBUG_FrustumCuller.CullCamera = game.Camera;
                    //renderer.DEBUG_FrustumCuller.UpdateVisibility();
                    //for (int i = 0; i < renderer.DebugMeshesRenderer.Elements.Count; i++)
                    //{
                    //    var el = renderer.DebugMeshesRenderer.Elements[i];

                    //    game.LineManager3D.AddBox(el.BoundingBox.dx(), new SlimDX.Color4(0, 1, 0));
                    //}

                    //visualizer.RenderNodeGroundBoundig(game, renderer.DEBUG_FrustumCuller.RootNode);
                    visualizer.RenderNodeGroundBoundig(game, renderer.DEBUG_FrustumCuller.RootNode,
                                                       delegate(FrustumCuller.CullNode quadTreeNode, out Color4 color4)
                    {
                        if (point.Views[2].IsNodeVisible(quadTreeNode))
                        {
                            color4 = new Color4(1, 0, 0);
                        }
                        else
                        {
                            color4 = new Color4(0, 1, 0);
                        }
                        return(true);
                    });
                }

                game.LineManager3D.AddViewFrustum(game.SpectaterCamera.ViewProjection, new SlimDX.Color4(1, 0, 0));
            };


            game.Run();
        }