public void TestHorizonSSAO() { var c = new OBJToRAMMeshConverter(new RAMTextureFactory()); var mesh = DefaultMeshes.CreateMerchantsHouseMesh(c); var game = new DX11Game(); game.InitDirectX(); var context = game.Device.ImmediateContext; var texturePool = new TexturePool(game); var gBuffer = new GBuffer(game.Device, 800, 600); var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool); var ssao = new HorizonSSAORenderer(game, 800, 600); var el = renderer.AddMesh(mesh); el.WorldMatrix = SlimDX.Matrix.Translation(MathHelper.Right * 0 * 2 + SlimDX.Vector3.UnitZ * 0 * 2); game.GameLoopEvent += delegate { gBuffer.Clear(); gBuffer.SetTargetsToOutputMerger(); renderer.Draw(); ssao.OnFrameRender(gBuffer.DepthRV, gBuffer.NormalRV); context.ClearState(); game.SetBackbuffer(); if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, gBuffer); } else { game.TextureRenderer.Draw(ssao.MSsaoBuffer.pSRV, new SlimDX.Vector2(0, 0), new SlimDX.Vector2(800, 600)); } }; game.Run(); }
public void TestMeshRendererSimple() { var game = new DX11Game(); game.InitDirectX(); var context = game.Device.ImmediateContext; var mesh = RenderingTestsHelper.CreateSimpleTestMesh(); var texturePool = new TexturePool(game); var gBuffer = new GBuffer(game.Device, 800, 600); var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool); 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(); } } } game.GameLoopEvent += delegate { gBuffer.Clear(); gBuffer.SetTargetsToOutputMerger(); context.Rasterizer.State = game.HelperStates.RasterizerShowAll; renderer.Draw(); context.ClearState(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, gBuffer); }; game.Run(); }
public void TestDeferredMeshRendererRenderCity() { 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 mesh = c.CreateMesh(importer); var game = new DX11Game(); game.InitDirectX(); var context = game.Device.ImmediateContext; var texturePool = new MHGameWork.TheWizards.Graphics.SlimDX.Rendering.Deferred.TexturePool(game); var gBuffer = new GBuffer(game.Device, 800, 600); var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool); var el = renderer.AddMesh(mesh); el.WorldMatrix = global::SlimDX.Matrix.Translation(MathHelper.Right * 0 * 2 + global::SlimDX.Vector3.UnitZ * 0 * 2); game.GameLoopEvent += delegate { gBuffer.Clear(); gBuffer.SetTargetsToOutputMerger(); renderer.Draw(); context.ClearState(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, gBuffer); }; global::SlimDX.Configuration.EnableObjectTracking = false; game.Run(); }
private void drawGBufferMeshes() { var cullCam = DEBUG_SeperateCullCamera; if (cullCam == null) { cullCam = game.Camera; } //TODO: fix culling+removing of elements //gbufferView.UpdateVisibility(cullCam.ViewProjection); //setMeshRendererVisibles(gbufferView); meshesRenderer.RasterizerState = rasterizerState; meshesRenderer.Draw(); foreach (var renderer in customGBufferRenderers) { renderer.Draw(); } context.Rasterizer.State = game.HelperStates.RasterizerShowAll; }
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 TestMeshRendererSimpleCulling() { var game = new DX11Game(); game.InitDirectX(); var context = game.Device.ImmediateContext; var mesh = RenderingTestsHelper.CreateSimpleTestMesh(); var texturePool = new TexturePool(game); var gBuffer = new GBuffer(game.Device, 800, 600); var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool); DeferredMeshElement middle = null; Vector3 radius = new Vector3(100, 1000, 100); FrustumCullerSimple culler = new FrustumCullerSimple(new BoundingBox(-radius, radius), 5); //QuadTreeVisualizer visualizer = new QuadTreeVisualizer(); SpectaterCamera cullCam = new SpectaterCamera(10f, 80); cullCam.Positie = new Vector3(8, 10, 8); cullCam.EnableUserInput = false; SpectaterCamera renderCam = game.SpectaterCamera; culler.CullCamera = cullCam; throw new NotImplementedException(); //renderer.Culler = culler; bool rotate = true; int selectedNode = -1; 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(); } } } game.GameLoopEvent += delegate { culler.UpdateVisibility(); if (rotate) { cullCam.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f); } cullCam.Update(game.Elapsed, game.Keyboard, game.Mouse); 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 Color col) //{ // col = Color.Red; // count++; // if (count == selectedNode) // { // node.Tag = "SELECTED!"; // } // return count == selectedNode; //}); } if (game.Keyboard.IsKeyPressed(Key.NumberPad0)) { rotate = !rotate; } game.LineManager3D.AddViewFrustum(new BoundingFrustum(cullCam.ViewProjection), new Color4()); //for (int i = 0; i < cullObjects.Count; i++) //{ // game.LineManager3D.AddBox(cullObjects[i].BoundingBox, Color.Red); //} //visualizer.RenderNodeGroundBoundig(game, culler.RootNode, // delegate(FrustumCuller.CullNode node, out Color col) // { // if (node.Visible) // { // col = Color.Orange; // } // else // { // col = Color.Green; // } // return true; // }); gBuffer.Clear(); gBuffer.SetTargetsToOutputMerger(); context.Rasterizer.State = game.HelperStates.RasterizerShowAll; renderer.Draw(); context.ClearState(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, gBuffer); }; game.Run(); }
public void TestMeshRendererAdvanced() { var texFactory = new RAMTextureFactory(); var c = new OBJToRAMMeshConverter(texFactory); var game = new DX11Game(); game.InitDirectX(); var context = game.Device.ImmediateContext; var importer = new ObjImporter(); importer.AddMaterialFileStream("Crate01.mtl", File.OpenRead(TestFiles.CrateMtl)); importer.ImportObjFile(TestFiles.CrateObj); var mesh = c.CreateMesh(importer); RAMMesh mesh2 = RenderingTestsHelper.CreateMerchantsHouseMesh(c); RAMMesh mesh3 = RenderingTestsHelper.CreateGuildHouseMesh(c); var gBuffer = new GBuffer(game.Device, 800, 600); DeferredMeshesRenderer renderer = InitDefaultMeshRenderer(game, gBuffer); var el = renderer.AddMesh(mesh); el.WorldMatrix = Matrix.Translation(MathHelper.Right * 0 * 2 + Vector3.UnitZ * 0 * 2); el = renderer.AddMesh(mesh2); el.WorldMatrix = Matrix.Translation(new Vector3(0, 0, 80)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { el = renderer.AddMesh(mesh3); el.WorldMatrix = Matrix.Translation(new Vector3(j * 30, 0, 70 + i * 30)); } } game.GameLoopEvent += delegate { gBuffer.Clear(); gBuffer.SetTargetsToOutputMerger(); context.Rasterizer.State = game.HelperStates.RasterizerShowAll; renderer.Draw(); context.ClearState(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, gBuffer); }; game.Run(); }