public void TestCreateTexture2D() { var game = new DX11Game(); game.InitDirectX(); var tex = new Texture2D(game.Device, new Texture2DDescription { ArraySize = 1, MipLevels = 1, Format = Format.B8G8R8A8_UNorm, Usage = ResourceUsage.Dynamic, CpuAccessFlags = CpuAccessFlags.Write, Width = 2, Height = 1, SampleDescription = new SampleDescription(1, 0), BindFlags = BindFlags.ShaderResource }); var box = game.Device.ImmediateContext.MapSubresource(tex, 0, 0, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None); box.Data.Write(new byte[] { 0, 0, 255, 255 }, 0, 4); game.Device.ImmediateContext.UnmapSubresource(tex, 0); var view = new ShaderResourceView(game.Device, tex); game.GameLoopEvent += delegate { game.TextureRenderer.Draw(view, Vector2.Zero, new Vector2(100, 100)); }; game.Run(); }
public void TestRenderUsingGDI() { var game = new DX11Game(); game.InitDirectX(); // Create the DirectX11 texture2D. This texture will be shared with the DirectX10 // device. The DirectX10 device will be used to render text onto this texture. DirectX11 // will then draw this texture (blended) onto the screen. // The KeyedMutex flag is required in order to share this resource. SlimDX.Direct3D11.Texture2D textureD3D11 = new Texture2D(game.Device, new Texture2DDescription { Width = 100, Height = 100, MipLevels = 1, ArraySize = 1, Format = Format.B8G8R8A8_UNorm, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.KeyedMutex }); var surface = textureD3D11.AsSurface(); var surface1 = Surface1.FromPointer(surface.ComPointer); game.GameLoopEvent += delegate { }; }
public void TestDeleteMeshNoMemoryLeak() { var game = new DX11Game(); game.InitDirectX(); var renderer = new DeferredRenderer(game); var mesh = UtilityMeshes.CreateBoxColored(new Color4(1, 0, 0), new Vector3(0.1f)); DeferredMeshElement[] elements = new DeferredMeshElement[100]; int i = 0; game.GameLoopEvent += delegate { elements[i] = renderer.CreateMeshElement(mesh); elements[i].WorldMatrix = Matrix.Translation((float)Math.Cos((float)i / elements.Length * MathHelper.TwoPi) * 5, 0, (float)Math.Sin((float)i / elements.Length * MathHelper.TwoPi) * 5); i = (i + 1) % elements.Length; //if (elements[i] != null) elements[i].Delete(); renderer.Draw(); }; game.Run(); }
private DX11Game createGame() { var ret = new DX11Game(); ret.InitDirectX(); return(ret); }
public void TestCombineFinalSSAO() { //TODO: add a way to show the specular in the alpha channel var game = new DX11Game(); game.InitDirectX(); var test = new DeferredTest.TestCombineFinalClass(game); var ssao = new HorizonSSAORenderer(game, 800, 600); game.GameLoopEvent += delegate { test.DrawUpdatedDeferredRendering(); ssao.OnFrameRender(test.FilledGBuffer.GBuffer.DepthRV, test.FilledGBuffer.GBuffer.NormalRV); game.Device.ImmediateContext.ClearState(); game.SetBackbuffer(); test.DrawCombined(ssao.MSsaoBuffer.pSRV); //game.TextureRenderer.Draw(ssao.MSsaoBuffer.pSRV, new SlimDX.Vector2(0, 0), // new SlimDX.Vector2(800, 600)); }; game.Run(); }
public void TestRenderManyMeshes() { var game = new DX11Game(); game.InitDirectX(); var renderer = new DeferredRenderer(game); var mesh = UtilityMeshes.CreateBoxColored(new Color4(1, 0, 0), new Vector3(0.1f)); DeferredMeshElement[] elements = new DeferredMeshElement[100]; for (int i = 0; i < elements.Length; i++) { elements[i] = renderer.CreateMeshElement(mesh); elements[i].WorldMatrix = Matrix.Translation((float)Math.Cos((float)i / elements.Length * MathHelper.TwoPi) * 5, 0, (float)Math.Sin((float)i / elements.Length * MathHelper.TwoPi) * 5); } game.GameLoopEvent += delegate { renderer.Draw(); }; game.Run(); }
public void TestCalculateIntersections() { var game = new DX11Game(); game.InitDirectX(); var size = 64; var target = new GPUHermiteCalculator(game); var signsTex = target.CreateDensitySignsTexture(size); target.WriteHermiteSigns(size, new Vector3(), new Vector3(), "", signsTex); var intersectionsTex = target.CreateIntersectionsTexture(size); var normals1Tex = target.CreateNormalsTexture(size); var normals2Tex = target.CreateNormalsTexture(size); var normals3Tex = target.CreateNormalsTexture(size); target.WriteHermiteIntersections(size, signsTex, intersectionsTex, normals1Tex, normals2Tex, normals3Tex); signsTex.SaveToImageSlices(game, TWDir.Test.CreateSubdirectory("DualContouring.GPU/Signs")); intersectionsTex.SaveToImageSlices(game, TWDir.Test.CreateSubdirectory("DualContouring.GPU/Intersections")); normals1Tex.SaveToImageSlices(game, TWDir.Test.CreateSubdirectory("DualContouring.GPU/Normals1")); normals2Tex.SaveToImageSlices(game, TWDir.Test.CreateSubdirectory("DualContouring.GPU/Normals2")); normals3Tex.SaveToImageSlices(game, TWDir.Test.CreateSubdirectory("DualContouring.GPU/Normals3")); }
public void TestSpotLightRendererShadowing() { var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var filledGBuffer = new TestFilledGBuffer(game, 800, 600); var light = new SpotLightRenderer(game, filledGBuffer.GBuffer); light.LightRadius *= 2; light.ShadowsEnabled = true; var toggle = false; game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); light.UpdateLightCamera(); game.Camera = light.LightCamera; light.UpdateShadowMap(filledGBuffer.Draw); game.Camera = game.SpectaterCamera; game.SetBackbuffer(); if (game.Keyboard.IsKeyPressed(Key.C)) { toggle = !toggle; } if (toggle) { light.SpotDirection = game.SpectaterCamera.CameraDirection; light.LightPosition = game.SpectaterCamera.CameraPosition; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { light.Draw(); game.TextureRenderer.Draw(light.ShadowMapRv, new Vector2(10, 10), new Vector2(300, 300)); game.LineManager3D.AddViewFrustum(light.LightCamera.ViewProjection, new Color4(1, 0, 0)); } }; game.Run(); }
public void TestToneMap() { var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var toneMap = new ToneMapRenderer(game); var hdrImage = Texture2D.FromFile(device, HdrImageDDS); var hdrImageRV = new ShaderResourceView(device, hdrImage); var avgLuminance = 1f; game.GameLoopEvent += delegate { if (game.Keyboard.IsKeyDown(Key.UpArrow)) { avgLuminance += game.Elapsed; } if (game.Keyboard.IsKeyDown(Key.DownArrow)) { avgLuminance -= game.Elapsed; } toneMap.DrawTonemapped(hdrImageRV, avgLuminance); }; game.Run(); }
public void TestDirectX11Game() { var game = new DX11Game(); game.InitDirectX(); game.Run(); }
public void TestRenderText() { var game = new DX11Game(); game.InitDirectX(); var txt = new TextTexture(game, 100, 100); txt.DrawText("The Wizards", new Vector2(0, 0), new Color4(0.3f, 0.3f, 0.3f)); txt.UpdateTexture(); game.GameLoopEvent += delegate { txt.Clear(); txt.DrawText("The Wizards", new Vector2(0, 0), new Color4(0.3f, 0.3f, 0.3f)); txt.UpdateTexture(); game.Device.ImmediateContext.OutputMerger.BlendState = game.HelperStates.AlphaBlend; game.TextureRenderer.Draw(txt.GPUTexture.View, new Vector2(0, 0), new Vector2(100, 100)); }; game.Run(); }
public void TestPhysicsDebugRenderer() { var game = new DX11Game(); game.InitDirectX(); PhysicsEngine engine = new PhysicsEngine(); engine.Initialize(); var debugRenderer = new PhysicsDebugRenderer(game, engine.Scene); debugRenderer.Initialize(); InitTestScene(engine.Scene); game.GameLoopEvent += delegate { engine.Update(game.Elapsed); debugRenderer.Render(); }; game.Run(); engine.Dispose(); }
public void BasicBalTest() { Emitter emit; DX11Game game = new DX11Game(); game.InitDirectX(); var texPool = new TexturePool(game); var testTexture = GetTestTexture(); BallParticleCreater creater = new BallParticleCreater(); //SimpleParticleCreater creater = new SimpleParticleCreater(); EmitterParameters param = new EmitterParameters(); param.texture = testTexture; param.particleCreater = creater; emit = new Emitter(texPool, game, param, 800, 600);//note: again screen size //game.Wpf.CreateClassForm(param); Seeder seed = new Seeder(54); var curve = Curve3D.CreateTestCurve(); emit.Initialize(); emit.InitializeRender(); emit.CreateRenderData(); emit.SetRenderData(); emit.SetPosition(Vector3.Zero); float dist = 0; game.GameLoopEvent += delegate { // emit.setShader(); emit.Update(); if (dist > 100) { dist = 0; } else { dist += game.Elapsed * 1; } //emit.SetPosition(new Vector3(dist, 0, 0)); Temp(dist, emit, curve); //Draw part //game.GraphicsDevice.Clear(Color.Black); game.Device.ImmediateContext.Rasterizer.State = game.HelperStates.RasterizerShowAll; emit.Render(game.SpectaterCamera.ViewProjection, game.SpectaterCamera.ViewInverse); }; game.Run(); }
public void TestBasicShaderIncludeRoot() { BasicShader shader = null; FullScreenQuad quad = null; var game = new DX11Game(); game.InitDirectX(); var fi = new FileInfo("../../Common.Core/Shaders/TestAutoReload.fx"); var include = new FileInfo("../../Common.Core/Shaders/IncludeTest.fx"); using (var fs = new StreamWriter(fi.OpenWrite())) { fs.WriteLine("float4 Color = float4(1,0,0,1);"); } using (var fs = new StreamWriter(include.OpenWrite())) { fs.WriteLine("float4 Color2 = float4(0,0,0,1);"); } shader = BasicShader.LoadAutoreload(game, fi); shader.SetTechnique("TestAutoReload"); quad = new FullScreenQuad(game.Device); var inputLayout = FullScreenQuad.CreateInputLayout(game.Device, shader.GetCurrentPass(0)); var time = 0f; game.GameLoopEvent += delegate { shader.Apply(); quad.Draw(inputLayout); if (time > 2 && time < 3) { using (var fs = new StreamWriter(fi.OpenWrite())) { fs.WriteLine("float4 Color = float4(1,1,0,1);"); time = 5; } } if (time > 6 && time < 7) { using (var fs = new StreamWriter(include.OpenWrite())) { fs.WriteLine("float4 Color2 = float4(-1,0,0,1);"); time = 10; } } time += game.Elapsed; }; game.Run(); }
public void TestTexture3D() { var game = new DX11Game(); game.InitDirectX(); int size = 64; saveTest3DTexture(game, size, "X", generateData(size, (x, y, z) => x % 2 == 0)); saveTest3DTexture(game, size, "Y", generateData(size, (x, y, z) => y % 2 == 0)); saveTest3DTexture(game, size, "Z", generateData(size, (x, y, z) => z % 2 == 0)); saveTest3DTexture(game, size, "Boundaries", generateDataBoxes(size)); }
public void FlameTest() { Emitter emit; DX11Game game = new DX11Game(); game.InitDirectX(); FlameParticleCreater creater; //game.DrawFps = true; //var pool = new VertexDeclarationPool(); //pool.SetVertexElements<Emitter.ParticleVertex>(Emitter.ParticleVertex.VertexElements); var texPool = new TexturePool(game); var testTexture = GetTestTexture(); creater = new FlameParticleCreater(); EmitterParameters param = new EmitterParameters(); param.EffectName = "calculateFlame"; param.texture = testTexture; param.particleCreater = creater; emit = new Emitter(texPool, game, param, 800, 600); Seeder seed = new Seeder(54); var curve = Curve3D.CreateTestCurve(); //texPool.Initialize(game); //pool.Initialize(game); emit.Initialize(); emit.InitializeRender(); emit.CreateRenderData(); emit.SetRenderData(); //emit.AddParticles(creater,1); float dist = 0; game.GameLoopEvent += delegate { dist += game.Elapsed; // emit.setShader(); //Temp(dist, emit, curve); //setColors(emit); emit.Update(); emit.Render(game.SpectaterCamera.ViewProjection, game.SpectaterCamera.ViewInverse); }; game.Run(); }
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 TestPointLightAccumulation() { //TODO: add a way to show the specular in the alpha channel var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var filledGBuffer = new TestFilledGBuffer(game, 800, 600); var light = new PointLightRenderer(game, filledGBuffer.GBuffer); var toggle = false; game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); game.SetBackbuffer(); if (game.Keyboard.IsKeyPressed(Key.C)) { toggle = !toggle; } if (toggle) { light.LightPosition = game.SpectaterCamera.CameraPosition; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { light.Draw(); } }; game.Run(); light.Dispose(); filledGBuffer.Dispose(); }
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(); }
public void TestDirectionalLightAccumulation() { //TODO: add a way to show the specular in the alpha channel var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var filledGBuffer = new TestFilledGBuffer(game, 800, 600); var light = new DirectionalLightRenderer(game, filledGBuffer.GBuffer); game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); game.SetBackbuffer(); if (game.Keyboard.IsKeyDown(Key.C)) { game.SpectaterCamera.Enabled = false; var mat = Matrix.RotationY(game.Mouse.RelativeX * game.Elapsed * 5) * Matrix.RotationX(game.Mouse.RelativeY * game.Elapsed * 5); light.LightDirection = Vector3.TransformNormal(light.LightDirection, mat); } else { game.SpectaterCamera.Enabled = true; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { light.Draw(); } }; game.Run(); }
public void TestLineManager3DFrustum() { var game = new DX11Game(); game.InitDirectX(); var mat = game.SpectaterCamera.ViewProjection; game.GameLoopEvent += delegate { if (game.Keyboard.IsKeyDown(Key.K)) { mat = game.SpectaterCamera.ViewProjection; } game.LineManager3D.AddViewFrustum(mat, new Color4(1, 0, 0)); }; game.Run(); }
public void TestCalculateDensityGridSigns() { var game = new DX11Game(); game.InitDirectX(); var size = 512; var offset = new Vector3(0, 0, 0); var scaling = new Vector3(1, 1, 1); var density = "20-v.y"; var target = new GPUHermiteCalculator(game); var tex = target.CreateDensitySignsTexture(size); target.WriteHermiteSigns(size, offset, scaling, density, tex); tex.SaveToImageSlices(game, TWDir.Test.CreateSubdirectory("DualContouring.GPU/Signs")); }
public void TestTextRendering() { var game = new DX11Game(); game.InitDirectX(); var wrapper = new DX11FontWrapper(game.Device); game.GameLoopEvent += delegate { wrapper.Draw("Welcome!", 128, 10, 10, new Color4(1, 0, 0)); wrapper.Draw("Welcome!", 128, 10, 210, new Color4(0, 1, 0)); wrapper.Draw("Welcome!", 128, 10, 410, new Color4(0, 0, 1)); //TODO: game.MarkFrameBuffer(); }; game.Run(); }
public void TestGBuffer() { var game = new DX11Game(); game.InitDirectX(); var buffer = new GBuffer(game.Device, 300, 300); buffer.Clear(); game.GameLoopEvent += delegate { ((Action) delegate { })(); DrawGBuffer(game, buffer); }; game.Run(); }
public void TestDeferredRendererLineElement() { var game = new DX11Game(); game.InitDirectX(); var renderer = new DeferredRenderer(game); var el = renderer.CreateLinesElement(); el.Lines.AddBox(new BoundingBox(Vector3.Zero, MathHelper.One), new Color4(1, 0, 0)); game.GameLoopEvent += delegate { renderer.Draw(); }; game.Run(); }
public void TestCombineFinalRenderer() { //TODO: add a way to show the specular in the alpha channel var game = new DX11Game(); game.InitDirectX(); var test = new TestCombineFinalClass(game); game.GameLoopEvent += delegate { test.DrawUpdatedDeferredRendering(); game.Device.ImmediateContext.ClearState(); game.SetBackbuffer(); test.DrawCombined(); }; game.Run(); }
public void TestRenderText() { var game = new DX11Game(); game.InitDirectX(); var Sprite = new SpriteRenderer(game.Device); Sprite.ScreenSize = new SlimDX.Vector2(800, 600); var myTextBlockRenderer = new TextBlockRenderer(Sprite, "Arial", FontWeight.Bold, FontStyle.Normal, FontStretch.Normal, 12); game.GameLoopEvent += delegate { myTextBlockRenderer.DrawString("Hello Wizard", new SlimDX.Vector2(20, 20), new SlimDX.Color4(1, 1, 1)); Sprite.Flush(); }; }
public static void ShowVoxelGrid(VoxelGrid grid) { var game = new DX11Game(); game.InitDirectX(); var renderer = new DeferredRenderer(game); var light = renderer.CreateDirectionalLight(); var ret = grid; IMesh voxelMesh = Voxelizer.CreateVoxelMesh(ret); var voxel = renderer.CreateMeshElement(voxelMesh); voxel.WorldMatrix = Matrix.Translation(0, 0, 0); game.GameLoopEvent += delegate { renderer.Draw(); }; game.Run(); }
public void TestDrawingToD3D11Conversion() { var bmp = createBitmap(); var game = new DX11Game(); game.InitDirectX(); var tex = GPUTexture.CreateCPUWritable(game, bmp.Width, bmp.Height, Format.B8G8R8A8_UNorm); var convert = new DrawingToD3D11Conversion(); convert.WriteBitmapToTexture(bmp, tex); game.GameLoopEvent += delegate { game.TextureRenderer.Draw(tex.View, Vector2.Zero, new Vector2(100, 100)); }; game.Run(); }