private void drawCombinedHdrImage(RenderTargetView output, GBuffer buffer, CombineFinalRenderer finalRenderer, ShaderResourceView background, ShaderResourceView ssao)
        {
            game.Device.ImmediateContext.ClearState();
            game.SetBackbuffer(); // This is to set default viewport only, because i am lazy

            context.OutputMerger.SetTargets(output);

            finalRenderer.DrawCombined(ssao);


            // Clear background to certain color
            context.OutputMerger.SetTargets(buffer.DepthStencilView, output);

            context.OutputMerger.DepthStencilState = backgroundDepthStencilState;

            game.TextureRenderer.Draw(background, new Vector2(), new Vector2(screenWidth, screenHeight));
        }
            public void Render()
            {
                angle += MathHelper.Pi * game.Elapsed;
                point.LightPosition = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), -2);

                ctx.ClearState();
                combineFinal.SetLightAccumulationStates();
                combineFinal.ClearLightAccumulation();
                point.Draw();

                ctx.ClearState();
                game.SetBackbuffer();
                ctx.Rasterizer.SetViewports(new Viewport(400, 300, 400, 300));

                combineFinal.DrawCombined();


                game.SetBackbuffer();
                GBufferTest.DrawGBuffer(game, buffer);
            }
示例#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();
        }
        public void drawMeshTest(IMesh mesh, Matrix worldMatrix)
        {
            var game = createGame();


            var pool = createTexturePool(game);

            var worldMesh = new WorldMesh {
                Mesh = mesh, WorldMatrix = worldMatrix
            };

            var meshes = new MeshesRenderer(new RendererResourcePool(new MeshRenderDataFactory(game, null, pool), pool, game), game);


            var ctx = game.Device.ImmediateContext;

            var gBuffer = createGBuffer(game);
            var scene   = new RenderingTestsHelper.SimpleLightedScene(game, gBuffer);


            var list = new List <WorldMesh>();

            list.Add(worldMesh);

            var buffer = gBuffer;

            ctx = game.Device.ImmediateContext;
            // Non-related init code

            var point = new PointLightRenderer(game, buffer);

            point.LightRadius    = 3;
            point.LightIntensity = 1;
            point.ShadowsEnabled = false;

            var angle = 0f;

            var combineFinal = new CombineFinalRenderer(game, buffer);

            var raster = new RasterizerStateDescription()
            {
                CullMode = CullMode.Front,
                FillMode = FillMode.Solid
            };

            var state = RasterizerState.FromDescription(game.Device, raster);

            point.LightRadius = 10;

            game.GameLoopEvent += delegate
            {
                ctx.ClearState();
                ctx.Rasterizer.State = state;
                gBuffer.Clear();
                gBuffer.SetTargetsToOutputMerger();

                meshes.DrawMeshes(list, game.Camera);

                angle += MathHelper.Pi * game.Elapsed;

                var alpha = 0.99f * game.Elapsed * 20000;

                var cam  = game.Camera.ViewInverse.GetTranslation();
                var diff = cam - point.LightPosition;
                diff.Normalize();


                point.LightPosition += diff * game.Elapsed * 2;// new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), -2);

                ctx.ClearState();
                combineFinal.SetLightAccumulationStates();
                combineFinal.ClearLightAccumulation();
                point.Draw();

                ctx.ClearState();
                game.SetBackbuffer();
                ctx.Rasterizer.SetViewports(new Viewport(400, 300, 400, 300));

                combineFinal.DrawCombined();


                game.SetBackbuffer();
                GBufferTest.DrawGBuffer(game, buffer);
            };

            game.Run();
        }
 public void DrawCombined()
 {
     combineFinal.DrawCombined();
 }