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 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(); }
private DX11Game createGame() { var ret = new DX11Game(); ret.InitDirectX(); return(ret); }
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 SurfaceMaterial(DX11Game game, ShaderResourceView diffuseTexture) { this.game = game; textures[0] = diffuseTexture; textures[1] = null; //normalTexture; textures[2] = null; //specularTexture; baseShader = BasicShader.LoadAutoreload(game, ShaderFiles.DCSurface, delegate { }, createShaderMacros()); baseShader.SetTechnique("DCSurface"); //baseShader.DiffuseTexture = checkerTexture; var desc = new SamplerDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, Filter = Filter.Anisotropic, MaximumAnisotropy = 16 }; sampler = SamplerState.FromDescription(game.Device, desc); inputLayout = CreateInputLayout(); }
public void TestPlayAnimation() { var controller = new AnimationControllerSkeleton(null); Skeleton skeleton; TheWizards.Animation.Animation animation; CreateTestAnimation(out skeleton, out animation); controller.SetAnimation(0, animation); var p = new Vector3(4, 5, 4); var m1 = Matrix.RotationAxis(Vector3.Normalize(new Vector3(-1, 4, 3)), 4) * Matrix.Translation(p); var m2 = Matrix.RotationAxis(Vector3.Normalize(new Vector3(3, 2, 8)), 4) * Matrix.Translation(p); var game = new DX11Game(); var visualizer = new SkeletonVisualizer(); game.GameLoopEvent += delegate { controller.ProgressTime(game.Elapsed); controller.UpdateSkeleton(); skeleton.UpdateAbsoluteMatrices(); visualizer.VisualizeSkeleton(game, skeleton); }; game.Run(); }
private GPUTexture3D(DX11Game game, Texture3DDescription desc) { Texture3D resource = new Texture3D(game.Device, desc); Resource = resource; View = new ShaderResourceView(resource.Device, Resource); }
public void VisualizeSkeleton(DX11Game game, Skeleton skeleton, Vector3 offset) { for (int i = 0; i < skeleton.Joints.Count; i++) { var joint = skeleton.Joints[i]; var c = Vector3.TransformCoordinate(Vector3.Zero, joint.AbsoluteMatrix) + offset; var x = Vector3.TransformCoordinate(Vector3.UnitX, joint.AbsoluteMatrix) + offset; var y = Vector3.TransformCoordinate(Vector3.UnitY, joint.AbsoluteMatrix) + offset; var z = Vector3.TransformCoordinate(Vector3.UnitZ, joint.AbsoluteMatrix) + offset; var p = c; if (joint.Parent != null) { p = Vector3.TransformCoordinate(Vector3.Zero, joint.Parent.AbsoluteMatrix) + offset; } game.LineManager3D.AddLine(p, c, new Color4(Color.White)); game.LineManager3D.AddLine(c, y, new Color4(Color.Green)); game.LineManager3D.AddLine(c, z, new Color4(Color.Blue)); game.LineManager3D.AddLine(c, x, new Color4(Color.Red)); } }
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 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 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 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(); }
private const int ThreadGroupSize = 8; // corresponds to shader public GaussianBlurFilter(DX11Game game) { this.game = game; context = game.Device.ImmediateContext; csX = loadComputeShader(CompiledShaderCache.Current.RootShaderPath + "Filters\\GaussianBlurCS.hlsl", "CSMAINX"); csY = loadComputeShader(CompiledShaderCache.Current.RootShaderPath + "Filters\\GaussianBlurCS.hlsl", "CSMAINY"); }
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(); }
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 DirectionalLightRenderer(DX11Game game, GBuffer gBuffer) { this.game = game; this.gBuffer = gBuffer; var device = game.Device; context = device.ImmediateContext; shadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\DirectionalLight.fx")); shadowsShader.SetTechnique("Technique0"); noShadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\DirectionalLight.fx"), null, new[] { new ShaderMacro("DISABLE_SHADOWS") }); noShadowsShader.SetTechnique("Technique0"); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, shadowsShader.GetCurrentPass(0)); LightDirection = Vector3.Normalize(new Vector3(1, 2, 1)); Color = new Vector3(1, 1, 0.9f); CSMRenderer = new CSM.CSMRenderer(game); }
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(); }
public DeferredMeshesRenderer(DX11Game game, GBuffer gBuffer, TexturePool texturePool) { this.game = game; this.pool = texturePool; ctx = game.Device.ImmediateContext; initialize(texturePool); }
public static DeferredMeshesRenderer InitDefaultMeshRenderer(DX11Game game, GBuffer gBuffer) { var texturePool = new TexturePool(game); var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool); return(renderer); }
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(); }
private static void saveTest3DTexture(DX11Game game, int size, string name, byte[] data) { var texture3D = GPUTexture3D.CreateCPUWritable(game, size, size, size, Format.R8G8B8A8_UNorm); texture3D.SetTextureRawData(data); Texture3D.SaveTextureToFile(game.Device.ImmediateContext, texture3D.Resource, ImageFileFormat.Dds, TWDir.Test.CreateSubdirectory("GPU").CreateFile(name + ".dds").FullName); texture3D.SaveToImageSlices(game, TWDir.Test.CreateSubdirectory("GPU").CreateSubdirectory(name)); }
public static void DrawGBuffer(DX11Game game, GBuffer buffer) { game.TextureRenderer.Draw(buffer.DiffuseRV, new Vector2(0, 0), new Vector2(400, 300)); game.TextureRenderer.Draw(buffer.NormalRV, new Vector2(400, 00), new Vector2(400, 300)); game.TextureRenderer.Draw(buffer.DepthRV, new Vector2(00, 300), new Vector2(400, 300)); }
/// <summary> /// Creates the renderer /// </summary> public CSMRenderer(DX11Game game) { this.game = game; var device = game.Device; context = device.ImmediateContext; // Load the effect we need shadowMapShader = BasicShader.LoadAutoreload(game, new FileInfo(CompiledShaderCache.Current.RootShaderPath + @"CSM\CSM.fx")); // Create the shadow map, using a 32-bit floating-point surface format shadowMap = new Texture2D(device, new Texture2DDescription { Width = ShadowMapSize * NumSplits, Height = ShadowMapSize, MipLevels = 1, ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, Format = global::SlimDX.DXGI.Format.R32_Typeless, SampleDescription = new global::SlimDX.DXGI.SampleDescription(1, 0) }); shadowMapDsv = new DepthStencilView(device, shadowMap, new DepthStencilViewDescription { ArraySize = 1, Dimension = DepthStencilViewDimension.Texture2D, Flags = DepthStencilViewFlags.None, Format = global::SlimDX.DXGI.Format.D32_Float, MipSlice = 0 }); ShadowMapRV = new ShaderResourceView(device, shadowMap, new ShaderResourceViewDescription { ArraySize = 1, Dimension = ShaderResourceViewDimension.Texture2D, MipLevels = 1, MostDetailedMip = 0, Format = global::SlimDX.DXGI.Format.R32_Float }); // Create the full-screen quad fullScreenQuad = new FullScreenQuad(device); // We'll keep an array of EffectTechniques that will let us map a // ShadowFilteringType to a technique for calculating shadow occlusion shadowOcclusionTechniques[0] = "CreateShadowTerm2x2PCF"; shadowOcclusionTechniques[1] = "CreateShadowTerm3x3PCF"; shadowOcclusionTechniques[2] = "CreateShadowTerm5x5PCF"; shadowOcclusionTechniques[3] = "CreateShadowTerm7x7PCF"; shadowMapShader.SetTechnique(shadowOcclusionTechniques[0]); layout = FullScreenQuad.CreateInputLayout(device, shadowMapShader.GetCurrentPass(0)); }
public static GPUTexture3D CreateCPUReadable(DX11Game game, int width, int height, int depth, Format format) { var desc = getBaseDesc(width, height, depth, format); desc.Usage = ResourceUsage.Staging; desc.CpuAccessFlags = CpuAccessFlags.Read; desc.BindFlags = BindFlags.None; return(new GPUTexture3D(new Texture3D(game.Device, desc), null, null)); }
public MeshRenderDataFactory(DX11Game game, BasicShader baseShader, TexturePool texturePool) { this.game = game; this.baseShader = baseShader; this.texturePool = texturePool; checkerTexture = Texture2D.FromFile(game.Device, TWDir.GameData.CreateSubdirectory("Core").FullName + "\\checker.png"); checkerTextureRV = new ShaderResourceView(game.Device, checkerTexture); }
public static GPUTexture3D CreateDefault(DX11Game game, int width, int height, int depth, Format format) { var desc = getBaseDesc(width, height, depth, format); desc.Usage = ResourceUsage.Default; desc.CpuAccessFlags = CpuAccessFlags.None; desc.BindFlags = BindFlags.ShaderResource; return(new GPUTexture3D(game, desc)); }
private void drawASFJoint(DX11Game game, ASFJoint joint, Vector3 pos) { for (int i = 0; i < joint.children.Count; i++) { var child = joint.children[i]; var end = pos + child.direction * child.length; game.LineManager3D.AddLine(pos, end, Color.White); drawASFJoint(game, child, end); } }