public void Draw(SpriteBatch spriteBatch) { sky.Draw(spriteBatch); stars.Draw(spriteBatch); moon.Draw(spriteBatch); sun.Draw(spriteBatch); clouds.Draw(spriteBatch); }
protected void DrawScene() { if (DrawCalls > 0u) { --DrawCalls; Sky.Draw(); foreach (var gameObject in Algs.DrawableObjectPouch.Redeem(DrawCalls == 0u)) { gameObject.Draw(); } } }
public override void DrawScene() { ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); var view = _camera.View; var proj = _camera.Proj; Effects.NormalMapFX.SetDirLights(_dirLights); Effects.NormalMapFX.SetEyePosW(_camera.Position); Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetEyePosW(_camera.Position); var floorTech = Effects.NormalMapFX.Light3TexTech; var activeTech = Effects.BasicFX.Light3Tech; ImmediateContext.InputAssembler.InputLayout = InputLayouts.PosNormalTexTan; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } for (var p = 0; p < floorTech.Description.PassCount; p++) { var pass = floorTech.GetPassByIndex(p); _grid.Draw(ImmediateContext, pass, view, proj); _cylinder.Draw(ImmediateContext, pass, view, proj); } for (var p = 0; p < activeTech.Description.PassCount; p++) { var pass = activeTech.GetPassByIndex(p); foreach (var firework in _fireworks) { firework.Render(ImmediateContext, pass, view, proj); } } _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); ImmediateContext.Rasterizer.State = null; }
/// <summary> /// Draws the SkinnedEffect demo. /// </summary> public override void Draw(GameTime gameTime) { // Compute camera matrices. const float cameraDistance = 100; Matrix view = Matrix.CreateTranslation(0, -40, 0) * Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation)) * Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) * Matrix.CreateLookAt(new Vector3(0, 0, -cameraDistance), new Vector3(0, 0, 0), Vector3.Up); Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 10000); // Draw the background. GraphicsDevice.Clear(Color.Black); sky.Draw(view, projection); DrawTitle("skinned effect", null, new Color(127, 112, 104)); // Draw the animating character. GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; Matrix[] bones = animationPlayer.GetSkinTransforms(); foreach (ModelMesh mesh in dude.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { effect.SetBoneTransforms(bones); effect.View = view; effect.Projection = projection; effect.EnableDefaultLighting(); effect.SpecularColor = Vector3.Zero; } mesh.Draw(); } base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1, 0); GraphicsDevice.RenderState.CullMode = CullMode.None; GraphicsDevice.RenderState.DepthBufferEnable = true; GraphicsDevice.RenderState.AlphaBlendEnable = false; GraphicsDevice.RenderState.AlphaTestEnable = false; person1.Model.Bones[0].Transform = person1.OriginalTransforms[0] * Matrix.CreateRotationX(camera.UpDownRot) * Matrix.CreateRotationY(camera.LeftRightRot); person1.Draw(camera); for (int i = 0; i < models.Count; i++) { models[i].Draw(camera); } foreach (ModelMesh mesh in terrain.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = Matrix.Identity; effect.SpecularColor = new Vector3(1, 0, 0); effect.View = camera.ViewMatrix; effect.Projection = camera.ProjectionMatrix; } mesh.Draw(); } sky.Draw(camera.ViewMatrix, camera.ProjectionMatrix); //Demo Stuff if (input.KeyDown(Keys.I)) { postProc.PostProcess("Invert"); } if (input.KeyDown(Keys.T)) { postProc.PostProcess("TimeChange", (float)gameTime.TotalGameTime.TotalMilliseconds / 1000.0f); } base.Draw(gameTime); }
public override void DrawScene() { ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } _terrain.Renderer.Draw(ImmediateContext, _camera, _dirLights); ImmediateContext.InputAssembler.InputLayout = InputLayouts.InstancedPosNormalTexTan; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; //var viewProj = _camera.ViewProj; Effects.InstancedNormalMapFX.SetDirLights(_dirLights); Effects.InstancedNormalMapFX.SetEyePosW(_camera.Position); /* * var activeTech = Effects.InstancedNormalMapFX.Light3TexTech; * for (int p = 0; p < activeTech.Description.PassCount; p++) { * * Effects.InstancedNormalMapFX.SetViewProj(viewProj); * Effects.InstancedNormalMapFX.SetTexTransform(Matrix.Identity); * * for (int i = 0; i < _treeModel.SubsetCount; i++) { * Effects.InstancedNormalMapFX.SetMaterial(_treeModel.Materials[i]); * Effects.InstancedNormalMapFX.SetDiffuseMap(_treeModel.DiffuseMapSRV[i]); * Effects.InstancedNormalMapFX.SetNormalMap(_treeModel.NormalMapSRV[i]); * * activeTech.GetPassByIndex(p).Apply(ImmediateContext); * _treeModel.ModelMesh.DrawInstanced(ImmediateContext, i, _instanceBuffer, _visibleTrees, Marshal.SizeOf(typeof(Matrix))); * } * * } */ ImmediateContext.Rasterizer.State = null; _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); }
public override void DrawScene() { ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } _terrain.Renderer.Draw(ImmediateContext, _camera, _dirLights); ImmediateContext.Rasterizer.State = null; _sky.Draw(ImmediateContext, _camera); _fire.EyePosW = _camera.Position; _fire.Draw(ImmediateContext, _camera); ImmediateContext.OutputMerger.BlendState = null; var blendFactor = new Color4(0, 0, 0, 0); ImmediateContext.OutputMerger.BlendFactor = blendFactor; ImmediateContext.OutputMerger.BlendSampleMask = -1; _rain.EyePosW = _camera.Position; _rain.EmitPosW = _camera.Position; _rain.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.BlendState = null; ImmediateContext.OutputMerger.BlendFactor = blendFactor; ImmediateContext.OutputMerger.BlendSampleMask = -1; ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); }
public override void DrawScene() { ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } _terrain.Renderer.Draw(ImmediateContext, _camera, _dirLights); ImmediateContext.Rasterizer.State = null; _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); }
public void Draw(SpriteBatch spriteBatch) { if (GameWorld.WorldData.IsTopDown) { // Draw a blue background to hide holes between ground and water in top down view. spriteBatch.Draw(ContentHelper.LoadTexture("Tiles/white"), new Rectangle(0, 0, TMBAW_Game.DefaultResWidth, TMBAW_Game.DefaultResHeight), new Color(65, 96, 228)); } else { Sky.Draw(spriteBatch); //if (_backgroundTexture != null) //{ // spriteBatch.Draw(_backgroundTexture, new Rectangle(0, 0, TMBAW_Game.DefaultResWidth, TMBAW_Game.DefaultResHeight), Color.White); //} if (GameWorld.WorldData.HasSun) { spriteBatch.Draw(_sun, new Rectangle(0, 0, TMBAW_Game.DefaultResWidth, TMBAW_Game.DefaultResHeight), Color.White); } if (_middlegroundTexture != null) { for (int i = 0; i < 3; i++) { spriteBatch.Draw(_middlegroundTexture, new Rectangle((int)middleCoords[i].X, (int)middleCoords[i].Y, TMBAW_Game.DefaultResWidth, TMBAW_Game.DefaultResHeight), Sky.GetAmbientLight()); } } if (_foregroundTexture != null) { for (int i = 0; i < 3; i++) { spriteBatch.Draw(_foregroundTexture, new Rectangle((int)foreCoords[i].X, (int)foreCoords[i].Y, TMBAW_Game.DefaultResWidth, TMBAW_Game.DefaultResHeight), Sky.GetAmbientLight()); } } } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { if (menu.Enabled) { menu.Draw(); } else { GraphicsDevice.Clear(Color.Black); sky.Draw(camera); GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; GraphicsDevice.RasterizerState = rs; terrain.Draw(gameTime); tankController.Draw(camera.View, projection); if (debug) { this.DrawDebugInfo(); } } base.Draw(gameTime); }
public override void DrawScene() { Effects.TerrainFX.SetSsaoMap(_whiteTex); Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV); Effects.TerrainFX.SetShadowTransform(_shadowTransform); _minimap.RenderMinimap(_dirLights); var view = _lightView; var proj = _lightProj; var viewProj = view * proj; _terrain.Renderer.DrawToShadowMap(ImmediateContext, _sMap, viewProj); DrawSceneToShadowMap(); ImmediateContext.Rasterizer.State = null; ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); ImmediateContext.Rasterizer.SetViewports(Viewport); _terrain.Renderer.ComputeSsao(ImmediateContext, _camera, _ssao, DepthStencilView); ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView); ImmediateContext.Rasterizer.SetViewports(Viewport); ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } if (Util.IsKeyDown(Keys.S)) { Effects.TerrainFX.SetSsaoMap(_whiteTex); } else { Effects.TerrainFX.SetSsaoMap(_ssao.AmbientSRV); } if (!Util.IsKeyDown(Keys.A)) { Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV); Effects.TerrainFX.SetShadowTransform(_shadowTransform); } else { Effects.TerrainFX.SetShadowMap(_whiteTex); } Effects.BasicFX.SetEyePosW(_camera.Position); Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetSsaoMap(_whiteTex); ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; for (var p = 0; p < Effects.BasicFX.Light1Tech.Description.PassCount; p++) { var pass = Effects.BasicFX.Light1Tech.GetPassByIndex(p); _unit.Render(ImmediateContext, pass, _camera.View, _camera.Proj); } _terrain.Renderer.Draw(ImmediateContext, _camera, _dirLights); ImmediateContext.Rasterizer.State = null; _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; _minimap.Draw(ImmediateContext); FontCache.DrawStrings( new[] { "Currently: " + _unit.Position, "Destination: " + _unit.Destination.MapPosition }, Vector2.Zero, Color.Yellow ); FontCache.DrawString("bold", "This is bold", new Vector2(Window.ClientSize.Width - 200, 0), Color.Red); EndFrame(); }
public override void DrawScene() { base.DrawScene(); ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); _camera.UpdateViewMatrix(); var view = _camera.View; var proj = _camera.Proj; var viewProj = _camera.ViewProj; var blendFactor = new Color4(0, 0, 0, 0); Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetEyePosW(_camera.Position); Effects.BasicFX.SetCubeMap(_sky.CubeMapSRV); Effects.NormalMapFX.SetDirLights(_dirLights); Effects.NormalMapFX.SetEyePosW(_camera.Position); Effects.NormalMapFX.SetCubeMap(_sky.CubeMapSRV); Effects.DisplacementMapFX.SetDirLights(_dirLights); Effects.DisplacementMapFX.SetEyePosW(_camera.Position); Effects.DisplacementMapFX.SetCubeMap(_sky.CubeMapSRV); Effects.DisplacementMapFX.SetHeightScale(0.05f); Effects.DisplacementMapFX.SetMaxTessDistance(1.0f); Effects.DisplacementMapFX.SetMinTessDistance(25.0f); Effects.DisplacementMapFX.SetMinTessFactor(1.0f); Effects.DisplacementMapFX.SetMaxTessFactor(5.0f); var activeTech = Effects.DisplacementMapFX.Light3Tech; var activeSphereTech = Effects.BasicFX.Light3ReflectTech; var activeSkullTech = Effects.BasicFX.Light3ReflectTech; switch (_renderOptions) { case RenderOptions.Basic: activeTech = Effects.BasicFX.Light3TexTech; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; break; case RenderOptions.NormalMap: activeTech = Effects.NormalMapFX.Light3TexTech; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; break; case RenderOptions.DisplacementMap: activeTech = Effects.DisplacementMapFX.Light3TexTech; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith3ControlPoints; break; } var stride = PosNormalTexTan.Stride; var offset = 0; ImmediateContext.InputAssembler.InputLayout = InputLayouts.PosNormalTexTan; ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_shapesVB, stride, offset)); ImmediateContext.InputAssembler.SetIndexBuffer(_shapesIB, Format.R32_UInt, 0); if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } for (int p = 0; p < activeTech.Description.PassCount; p++) { var world = _gridWorld; var wit = MathF.InverseTranspose(world); var wvp = world * viewProj; switch (_renderOptions) { case RenderOptions.Basic: Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(wit); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Scaling(8, 10, 1)); Effects.BasicFX.SetMaterial(_gridMat); Effects.BasicFX.SetDiffuseMap(_stoneTexSRV); break; case RenderOptions.NormalMap: Effects.NormalMapFX.SetWorld(world); Effects.NormalMapFX.SetWorldInvTranspose(wit); Effects.NormalMapFX.SetWorldViewProj(wvp); Effects.NormalMapFX.SetTexTransform(Matrix.Scaling(8, 10, 1)); Effects.NormalMapFX.SetMaterial(_gridMat); Effects.NormalMapFX.SetDiffuseMap(_stoneTexSRV); Effects.NormalMapFX.SetNormalMap(_stoneNormalTexSRV); break; case RenderOptions.DisplacementMap: Effects.DisplacementMapFX.SetWorld(world); Effects.DisplacementMapFX.SetWorldInvTranspose(wit); Effects.DisplacementMapFX.SetViewProj(viewProj); Effects.DisplacementMapFX.SetWorldViewProj(wvp); Effects.DisplacementMapFX.SetTexTransform(Matrix.Scaling(8, 10, 1)); Effects.DisplacementMapFX.SetMaterial(_gridMat); Effects.DisplacementMapFX.SetDiffuseMap(_stoneTexSRV); Effects.DisplacementMapFX.SetNormalMap(_stoneNormalTexSRV); break; } var pass = activeTech.GetPassByIndex(p); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_gridIndexCount, _gridIndexOffset, _gridVertexOffset); world = _boxWorld; wit = MathF.InverseTranspose(world); wvp = world * viewProj; switch (_renderOptions) { case RenderOptions.Basic: Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(wit); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Scaling(2, 1, 1)); Effects.BasicFX.SetMaterial(_boxMat); Effects.BasicFX.SetDiffuseMap(_brickTexSRV); break; case RenderOptions.NormalMap: Effects.NormalMapFX.SetWorld(world); Effects.NormalMapFX.SetWorldInvTranspose(wit); Effects.NormalMapFX.SetWorldViewProj(wvp); Effects.NormalMapFX.SetTexTransform(Matrix.Scaling(2, 1, 1)); Effects.NormalMapFX.SetMaterial(_boxMat); Effects.NormalMapFX.SetDiffuseMap(_brickTexSRV); Effects.NormalMapFX.SetNormalMap(_brickNormalTexSRV); break; case RenderOptions.DisplacementMap: Effects.DisplacementMapFX.SetWorld(world); Effects.DisplacementMapFX.SetWorldInvTranspose(wit); Effects.DisplacementMapFX.SetViewProj(viewProj); Effects.DisplacementMapFX.SetWorldViewProj(wvp); Effects.DisplacementMapFX.SetTexTransform(Matrix.Scaling(2, 1, 1)); Effects.DisplacementMapFX.SetMaterial(_boxMat); Effects.DisplacementMapFX.SetDiffuseMap(_brickTexSRV); Effects.DisplacementMapFX.SetNormalMap(_brickNormalTexSRV); break; } pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_boxIndexCount, _boxIndexOffset, _boxVertexOffset); foreach (var matrix in _cylWorld) { world = matrix; wit = MathF.InverseTranspose(world); wvp = world * viewProj; switch (_renderOptions) { case RenderOptions.Basic: Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(wit); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Scaling(1, 2, 1)); Effects.BasicFX.SetMaterial(_cylinderMat); Effects.BasicFX.SetDiffuseMap(_brickTexSRV); break; case RenderOptions.NormalMap: Effects.NormalMapFX.SetWorld(world); Effects.NormalMapFX.SetWorldInvTranspose(wit); Effects.NormalMapFX.SetWorldViewProj(wvp); Effects.NormalMapFX.SetTexTransform(Matrix.Scaling(1, 2, 1)); Effects.NormalMapFX.SetMaterial(_cylinderMat); Effects.NormalMapFX.SetDiffuseMap(_brickTexSRV); Effects.NormalMapFX.SetNormalMap(_brickNormalTexSRV); break; case RenderOptions.DisplacementMap: Effects.DisplacementMapFX.SetWorld(world); Effects.DisplacementMapFX.SetWorldInvTranspose(wit); Effects.DisplacementMapFX.SetViewProj(viewProj); Effects.DisplacementMapFX.SetWorldViewProj(wvp); Effects.DisplacementMapFX.SetTexTransform(Matrix.Scaling(1, 2, 1)); Effects.DisplacementMapFX.SetMaterial(_cylinderMat); Effects.DisplacementMapFX.SetDiffuseMap(_brickTexSRV); Effects.DisplacementMapFX.SetNormalMap(_brickNormalTexSRV); break; } pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_cylinderIndexCount, _cylinderIndexOffset, _cylinderVertexOffset); } } ImmediateContext.HullShader.Set(null); ImmediateContext.DomainShader.Set(null); ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; for (int p = 0; p < activeSphereTech.Description.PassCount; p++) { foreach (var matrix in _sphereWorld) { var world = matrix; var wit = MathF.InverseTranspose(world); var wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(wit); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_sphereMat); activeSphereTech.GetPassByIndex(p).Apply(ImmediateContext); ImmediateContext.DrawIndexed(_sphereIndexCount, _sphereIndexOffset, _sphereVertexOffset); } } stride = Basic32.Stride; offset = 0; ImmediateContext.Rasterizer.State = null; ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_skullVB, stride, offset)); ImmediateContext.InputAssembler.SetIndexBuffer(_skullIB, Format.R32_UInt, 0); for (int p = 0; p < activeSkullTech.Description.PassCount; p++) { var world = _skullWorld; var wit = MathF.InverseTranspose(world); var wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(wit); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetMaterial(_skullMat); activeSkullTech.GetPassByIndex(p).Apply(ImmediateContext); ImmediateContext.DrawIndexed(_skullIndexCount, 0, 0); } _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); }
public override void DrawScene() { ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; _camera.UpdateViewMatrix(); Matrix view = _camera.View; Matrix proj = _camera.Proj; Matrix viewProj = _camera.ViewProj; Effects.BasicFX.SetEyePosW(_camera.Position); Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetCubeMap(_sky.CubeMapSRV); var activeTexTech = Effects.BasicFX.Light1TexTech; var activeSkullTech = Effects.BasicFX.Light1ReflectTech; var activeReflectTech = Effects.BasicFX.Light1TexReflectTech; switch (_lightCount) { case 1: activeTexTech = Effects.BasicFX.Light1TexTech; activeSkullTech = Effects.BasicFX.Light1ReflectTech; activeReflectTech = Effects.BasicFX.Light1TexReflectTech; break; case 2: activeTexTech = Effects.BasicFX.Light2TexTech; activeSkullTech = Effects.BasicFX.Light2ReflectTech; activeReflectTech = Effects.BasicFX.Light2TexReflectTech; break; case 3: activeTexTech = Effects.BasicFX.Light3TexTech; activeSkullTech = Effects.BasicFX.Light3ReflectTech; activeReflectTech = Effects.BasicFX.Light3TexReflectTech; break; } // draw grid, box, cylinders without reflection for (var p = 0; p < activeTexTech.Description.PassCount; p++) { var pass = activeTexTech.GetPassByIndex(p); ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_shapesVB, Basic32.Stride, 0)); ImmediateContext.InputAssembler.SetIndexBuffer(_shapesIB, Format.R32_UInt, 0); var world = _gridWorld; var worldInvTranspose = MathF.InverseTranspose(world); var wvp = world * view * proj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Scaling(6, 8, 1)); Effects.BasicFX.SetMaterial(_gridMat); Effects.BasicFX.SetDiffuseMap(_floorTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_gridIndexCount, _gridIndexOffset, _gridVertexOffset); world = _boxWorld; worldInvTranspose = MathF.InverseTranspose(world); wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_boxMat); Effects.BasicFX.SetDiffuseMap(_stoneTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_boxIndexCount, _boxIndexOffset, _boxVertexOffset); foreach (var matrix in _cylWorld) { world = matrix; worldInvTranspose = MathF.InverseTranspose(world); wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_cylinderMat); Effects.BasicFX.SetDiffuseMap(_brickTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_cylinderIndexCount, _cylinderIndexOffset, _cylinderVertexOffset); } } // draw spheres with reflection for (var p = 0; p < activeReflectTech.Description.PassCount; p++) { var pass = activeReflectTech.GetPassByIndex(p); Matrix world; Matrix worldInvTranspose; Matrix wvp; foreach (var matrix in _sphereWorld) { world = matrix; worldInvTranspose = MathF.InverseTranspose(world); wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_sphereMat); Effects.BasicFX.SetDiffuseMap(_stoneTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_sphereIndexCount, _sphereIndexOffset, _sphereVertexOffset); } } for (int p = 0; p < activeSkullTech.Description.PassCount; p++) { var pass = activeSkullTech.GetPassByIndex(p); ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_skullVB, Basic32.Stride, 0)); ImmediateContext.InputAssembler.SetIndexBuffer(_skullIB, Format.R32_UInt, 0); var world = _skullWorld; var worldInvTranspose = MathF.InverseTranspose(world); var wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetMaterial(_skullMat); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_skullIndexCount, 0, 0); } _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); }
public override void DrawScene() { Effects.TerrainFX.SetSsaoMap(_whiteTex); Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV); Effects.TerrainFX.SetShadowTransform(_shadowTransform); _minimap.RenderMinimap(_dirLights); var view = _lightView; var proj = _lightProj; var viewProj = view * proj; _terrain.Renderer.DrawToShadowMap(ImmediateContext, _sMap, viewProj); ImmediateContext.Rasterizer.State = null; ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); ImmediateContext.Rasterizer.SetViewports(Viewport); _terrain.Renderer.ComputeSsao(ImmediateContext, _camera, _ssao, DepthStencilView); ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView); ImmediateContext.Rasterizer.SetViewports(Viewport); ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } if (Util.IsKeyDown(Keys.S)) { Effects.TerrainFX.SetSsaoMap(_whiteTex); } else { Effects.TerrainFX.SetSsaoMap(_ssao.AmbientSRV); } if (!Util.IsKeyDown(Keys.A)) { Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV); Effects.TerrainFX.SetShadowTransform(_shadowTransform); } else { Effects.TerrainFX.SetShadowMap(_whiteTex); } Effects.BasicFX.SetEyePosW(_camera.Position); Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetSsaoMap(_whiteTex); Effects.BasicFX.SetSsaoMap(_whiteTex); if (_showSphere) { _sphere.World = Matrix.Translation(_spherePos); for (var p = 0; p < Effects.BasicFX.Light1Tech.Description.PassCount; p++) { var pass = Effects.BasicFX.Light1Tech.GetPassByIndex(p); _sphere.Draw(ImmediateContext, pass, _camera.View, _camera.Proj, RenderMode.Basic); } } _terrain.Renderer.Draw(ImmediateContext, _camera, _dirLights); ImmediateContext.Rasterizer.State = null; _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; _minimap.Draw(ImmediateContext); SwapChain.Present(0, PresentFlags.None); }
public override void DrawScene() { ImmediateContext.Rasterizer.State = null; ImmediateContext.ClearDepthStencilView( DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0 ); ImmediateContext.Rasterizer.SetViewports(Viewport); _ssao.SetNormalDepthRenderTarget(DepthStencilView); DrawSceneToSsaoNormalDepthMap(); _ssao.ComputeSsao(_camera); _ssao.BlurAmbientMap(4); ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView); ImmediateContext.Rasterizer.SetViewports(Viewport); ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); var viewProj = _camera.ViewProj; var view = _camera.View; var proj = _camera.Proj; Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetEyePosW(_camera.Position); //Effects.BasicFX.SetCubeMap(_sky.CubeMapSRV); Effects.NormalMapFX.SetDirLights(_dirLights); Effects.NormalMapFX.SetEyePosW(_camera.Position); //Effects.NormalMapFX.SetCubeMap(_sky.CubeMapSRV); if (!Util.IsKeyDown(Keys.S)) { Effects.BasicFX.SetSsaoMap(_ssao.AmbientSRV); Effects.NormalMapFX.SetSsaoMap(_ssao.AmbientSRV); } else { Effects.BasicFX.SetSsaoMap(_texMgr.CreateTexture("Textures/white.dds")); Effects.NormalMapFX.SetSsaoMap(_texMgr.CreateTexture("Textures/white.dds")); } var toTexSpace = Matrix.Scaling(0.5f, -0.5f, 1.0f) * Matrix.Translation(0.5f, 0.5f, 0); var activeTech = Effects.NormalMapFX.Light3Tech; var activeSphereTech = Effects.BasicFX.Light3ReflectTech; var activeSkullTech = Effects.BasicFX.Light3ReflectTech; ImmediateContext.InputAssembler.InputLayout = InputLayouts.PosNormalTexTan; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } for (var p = 0; p < activeTech.Description.PassCount; p++) { // draw grid var pass = activeTech.GetPassByIndex(p); _grid.ToTexSpace = toTexSpace; _grid.Draw(ImmediateContext, pass, view, proj); // draw box _box.ToTexSpace = toTexSpace; _box.Draw(ImmediateContext, pass, view, proj); // draw columns foreach (var cylinder in _cylinders) { cylinder.ToTexSpace = toTexSpace; cylinder.Draw(ImmediateContext, pass, view, proj); } } ImmediateContext.HullShader.Set(null); ImmediateContext.DomainShader.Set(null); ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; for (var p = 0; p < activeSphereTech.Description.PassCount; p++) { var pass = activeSphereTech.GetPassByIndex(p); foreach (var sphere in _spheres) { sphere.ToTexSpace = toTexSpace; sphere.Draw(ImmediateContext, pass, view, proj, RenderMode.Basic); } } ImmediateContext.Rasterizer.State = null; ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; for (var p = 0; p < activeSkullTech.Description.PassCount; p++) { _skull.ToTexSpace = toTexSpace; _skull.Draw(ImmediateContext, activeSkullTech.GetPassByIndex(p), view, proj, RenderMode.Basic); } ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; DrawScreenQuad(_ssao.AmbientSRV); DrawScreenQuad2(_ssao.NormalDepthSRV); _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; var srvs = new List <ShaderResourceView>(); for (var i = 0; i < 16; i++) { srvs.Add(null); } ImmediateContext.PixelShader.SetShaderResources(srvs.ToArray(), 0, 16); SwapChain.Present(0, PresentFlags.None); }
private void DrawScene(CameraBase camera, bool drawCenterSphere) { ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; Matrix view = camera.View; Matrix proj = camera.Proj; Matrix viewProj = camera.ViewProj; Effects.BasicFX.SetEyePosW(camera.Position); Effects.BasicFX.SetDirLights(_dirLights); var activeTexTech = Effects.BasicFX.Light1TexTech; var activeSkullTech = Effects.BasicFX.Light1ReflectTech; var activeReflectTech = Effects.BasicFX.Light1TexReflectTech; switch (_lightCount) { case 1: activeTexTech = Effects.BasicFX.Light1TexTech; activeSkullTech = Effects.BasicFX.Light1ReflectTech; activeReflectTech = Effects.BasicFX.Light1TexReflectTech; break; case 2: activeTexTech = Effects.BasicFX.Light2TexTech; activeSkullTech = Effects.BasicFX.Light2ReflectTech; activeReflectTech = Effects.BasicFX.Light2TexReflectTech; break; case 3: activeTexTech = Effects.BasicFX.Light3TexTech; activeSkullTech = Effects.BasicFX.Light3ReflectTech; activeReflectTech = Effects.BasicFX.Light3TexReflectTech; break; } for (int p = 0; p < activeSkullTech.Description.PassCount; p++) { var pass = activeSkullTech.GetPassByIndex(p); ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_skullVB, Basic32.Stride, 0)); ImmediateContext.InputAssembler.SetIndexBuffer(_skullIB, Format.R32_UInt, 0); var world = _skullWorld; var worldInvTranspose = MathF.InverseTranspose(world); var wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetMaterial(_skullMat); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_skullIndexCount, 0, 0); } // draw grid, box, cylinders without reflection for (var p = 0; p < activeTexTech.Description.PassCount; p++) { var pass = activeTexTech.GetPassByIndex(p); ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_shapesVB, Basic32.Stride, 0)); ImmediateContext.InputAssembler.SetIndexBuffer(_shapesIB, Format.R32_UInt, 0); var world = _gridWorld; var worldInvTranspose = MathF.InverseTranspose(world); var wvp = world * view * proj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Scaling(6, 8, 1)); Effects.BasicFX.SetMaterial(_gridMat); Effects.BasicFX.SetDiffuseMap(_floorTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_gridIndexCount, _gridIndexOffset, _gridVertexOffset); world = _boxWorld; worldInvTranspose = MathF.InverseTranspose(world); wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_boxMat); Effects.BasicFX.SetDiffuseMap(_stoneTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_boxIndexCount, _boxIndexOffset, _boxVertexOffset); foreach (var matrix in _cylWorld) { world = matrix; worldInvTranspose = MathF.InverseTranspose(world); wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_cylinderMat); Effects.BasicFX.SetDiffuseMap(_brickTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_cylinderIndexCount, _cylinderIndexOffset, _cylinderVertexOffset); } foreach (var matrix in _sphereWorld) { world = matrix; worldInvTranspose = MathF.InverseTranspose(world); wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(worldInvTranspose); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_sphereMat); Effects.BasicFX.SetDiffuseMap(_stoneTexSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_sphereIndexCount, _sphereIndexOffset, _sphereVertexOffset); } } if (drawCenterSphere) { for (int p = 0; p < activeReflectTech.Description.PassCount; p++) { var pass = activeReflectTech.GetPassByIndex(p); var world = _centerSphereWorld; var wit = MathF.InverseTranspose(world); var wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(wit); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetTexTransform(Matrix.Identity); Effects.BasicFX.SetMaterial(_centerSphereMat); Effects.BasicFX.SetDiffuseMap(_stoneTexSRV); Effects.BasicFX.SetCubeMap(_dynamicCubeMapSRV); pass.Apply(ImmediateContext); ImmediateContext.DrawIndexed(_sphereIndexCount, _sphereIndexOffset, _sphereVertexOffset); } } _sky.Draw(ImmediateContext, camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; }
public void TickRender() { _Sky.Draw(); }
public override void DrawScene() { ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); var viewProj = _camera.ViewProj; var view = _camera.View; var proj = _camera.Proj; Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetEyePosW(_camera.Position); Effects.BasicFX.SetCubeMap(_sky.CubeMapSRV); Effects.NormalMapFX.SetDirLights(_dirLights); Effects.NormalMapFX.SetEyePosW(_camera.Position); Effects.NormalMapFX.SetCubeMap(_sky.CubeMapSRV); Effects.DisplacementMapFX.SetDirLights(_dirLights); Effects.DisplacementMapFX.SetEyePosW(_camera.Position); Effects.DisplacementMapFX.SetCubeMap(_sky.CubeMapSRV); Effects.DisplacementMapFX.SetHeightScale(0.07f); Effects.DisplacementMapFX.SetMaxTessDistance(1.0f); Effects.DisplacementMapFX.SetMinTessDistance(25.0f); Effects.DisplacementMapFX.SetMinTessFactor(1.0f); Effects.DisplacementMapFX.SetMaxTessFactor(5.0f); Effects.WavesFX.SetDirLights(_dirLights); Effects.WavesFX.SetEyePosW(_camera.Position); Effects.WavesFX.SetCubeMap(_sky.CubeMapSRV); Effects.WavesFX.SetHeightScale0(0.4f); Effects.WavesFX.SetHeightScale1(1.2f); Effects.WavesFX.SetMaxTessDistance(4.0f); Effects.WavesFX.SetMinTessDistance(30.0f); Effects.WavesFX.SetMinTessFactor(2.0f); Effects.WavesFX.SetMaxTessFactor(6.0f); var activeSkullTech = Effects.BasicFX.Light3ReflectTech; var waveTech = Effects.WavesFX.Light3ReflectTech; var activeTech = Effects.DisplacementMapFX.Light3TexTech; var activeSphereTech = Effects.BasicFX.Light3ReflectTech; ImmediateContext.InputAssembler.InputLayout = InputLayouts.PosNormalTexTan; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith3ControlPoints; if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } _waves.Draw(ImmediateContext, waveTech, viewProj); for (var p = 0; p < activeTech.Description.PassCount; p++) { var pass = activeTech.GetPassByIndex(p); _box.Draw(ImmediateContext, pass, view, proj, RenderMode.DisplacementMapped); // draw columns foreach (var cylinder in _cylinders) { cylinder.Draw(ImmediateContext, pass, view, proj, RenderMode.DisplacementMapped); } } ImmediateContext.HullShader.Set(null); ImmediateContext.DomainShader.Set(null); ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; for (var p = 0; p < activeSphereTech.Description.PassCount; p++) { var pass = activeSphereTech.GetPassByIndex(p); foreach (var sphere in _spheres) { sphere.Draw(ImmediateContext, pass, view, proj, RenderMode.Basic); } } ImmediateContext.Rasterizer.State = null; for (var p = 0; p < activeSkullTech.Description.PassCount; p++) { _skull.Draw(ImmediateContext, activeSkullTech.GetPassByIndex(p), view, proj, RenderMode.Basic); } _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); }
public override void DrawScene() { Effects.BasicFX.SetShadowMap(null); Effects.NormalMapFX.SetShadowMap(null); _sMap.BindDsvAndSetNullRenderTarget(ImmediateContext); DrawSceneToShadowMap(); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView); ImmediateContext.Rasterizer.SetViewports(Viewport); ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); var viewProj = _camera.ViewProj; var view = _camera.View; var proj = _camera.Proj; Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetEyePosW(_camera.Position); Effects.BasicFX.SetCubeMap(_sky.CubeMapSRV); Effects.BasicFX.SetShadowMap(_sMap.DepthMapSRV); Effects.NormalMapFX.SetDirLights(_dirLights); Effects.NormalMapFX.SetEyePosW(_camera.Position); Effects.NormalMapFX.SetCubeMap(_sky.CubeMapSRV); Effects.NormalMapFX.SetShadowMap(_sMap.DepthMapSRV); var activeTech = Effects.NormalMapFX.Light3TexTech; var activeSphereTech = Effects.BasicFX.Light3ReflectTech; var activeSkullTech = Effects.BasicFX.Light3ReflectTech; ImmediateContext.InputAssembler.InputLayout = InputLayouts.PosNormalTexTan; if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } for (var p = 0; p < activeTech.Description.PassCount; p++) { // draw grid var pass = activeTech.GetPassByIndex(p); _grid.ShadowTransform = _shadowTransform; _grid.Draw(ImmediateContext, pass, view, proj); // draw box _box.ShadowTransform = _shadowTransform; _box.Draw(ImmediateContext, pass, view, proj); // draw columns foreach (var cylinder in _cylinders) { cylinder.ShadowTransform = _shadowTransform; cylinder.Draw(ImmediateContext, pass, view, proj); } } ImmediateContext.HullShader.Set(null); ImmediateContext.DomainShader.Set(null); ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; for (var p = 0; p < activeSphereTech.Description.PassCount; p++) { var pass = activeSphereTech.GetPassByIndex(p); foreach (var sphere in _spheres) { sphere.ShadowTransform = _shadowTransform; sphere.Draw(ImmediateContext, pass, view, proj, RenderMode.Basic); } } var stride = Basic32.Stride; const int offset = 0; ImmediateContext.Rasterizer.State = null; ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_skullVB, stride, offset)); ImmediateContext.InputAssembler.SetIndexBuffer(_skullIB, Format.R32_UInt, 0); for (var p = 0; p < activeSkullTech.Description.PassCount; p++) { var world = _skullWorld; var wit = MathF.InverseTranspose(world); var wvp = world * viewProj; Effects.BasicFX.SetWorld(world); Effects.BasicFX.SetWorldInvTranspose(wit); Effects.BasicFX.SetWorldViewProj(wvp); Effects.BasicFX.SetShadowTransform(world * _shadowTransform); Effects.BasicFX.SetMaterial(_skullMat); activeSkullTech.GetPassByIndex(p).Apply(ImmediateContext); ImmediateContext.DrawIndexed(_skullIndexCount, 0, 0); } DrawScreenQuad(); _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; SwapChain.Present(0, PresentFlags.None); }
public override void DrawScene() { Effects.TerrainFX.SetSsaoMap(_whiteTex); Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV); Effects.TerrainFX.SetShadowTransform(_shadowTransform); _minimap.RenderMinimap(_dirLights); var viewProj = _lightView * _lightProj; _terrain.Renderer.DrawToShadowMap(ImmediateContext, _sMap, viewProj); ImmediateContext.Rasterizer.State = null; ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); ImmediateContext.Rasterizer.SetViewports(Viewport); _terrain.Renderer.ComputeSsao(ImmediateContext, _camera, _ssao, DepthStencilView); ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView); ImmediateContext.Rasterizer.SetViewports(Viewport); ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } if (Util.IsKeyDown(Keys.S)) { Effects.TerrainFX.SetSsaoMap(_whiteTex); } else { Effects.TerrainFX.SetSsaoMap(_ssao.AmbientSRV); } Effects.TerrainFX.SetShadowMap(_sMap.DepthMapSRV); Effects.TerrainFX.SetShadowTransform(_shadowTransform); if (!Util.IsKeyDown(Keys.A)) { _terrain.Renderer.Shadows = true; } else { _terrain.Renderer.Shadows = false; } _terrain.Renderer.Draw(ImmediateContext, _camera, _dirLights); ImmediateContext.Rasterizer.State = null; _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; DrawScreenQuad(_ssao.AmbientSRV); DrawScreenQuad2(_ssao.NormalDepthSRV); DrawScreenQuad3(_sMap.DepthMapSRV); _minimap.Draw(ImmediateContext); SwapChain.Present(0, PresentFlags.None); }