Example #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();
        }
Example #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();
        }
Example #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();
        }
Example #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();
        }