private void ClearTargets() { _immediateContext.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0); //_immediateContext.ClearRenderTargetView(renderView, ambient); _immediateContext.ClearRenderTargetView(gBufferLightView, Color4.Black); _immediateContext.ClearRenderTargetView(gBufferNormalView, Color4.Black); _immediateContext.ClearRenderTargetView(gBufferDiffuseView, Color4.Black); }
public void ClearDepth(DeviceContext context) { if (!UseDepth) { return; } if (Multisampled) { context.ClearDepthStencilView(MSDSV, DepthStencilClearFlags.Depth, 1.0f, 0); } else { context.ClearDepthStencilView(DSV, DepthStencilClearFlags.Depth, 1.0f, 0); } }
void Bind(DeviceContext context) { RenderTargetView rtv = null; context.OutputMerger.SetRenderTargets(depthMap, rtv); context.ClearDepthStencilView(depthMap, DepthStencilClearFlags.Depth, 1f, 0); }
protected override void DrawPrepare() { base.DrawPrepare(); if (Sun != null && UseShadows) { _sunShadows.Update(Sun.Direction, Camera); _sunShadows.DrawScene(DeviceContextHolder, this); } if (UseCubemapReflections) { _reflectionCubemap.Update(ReflectionCubemapPosition); _reflectionCubemap.DrawScene(DeviceContextHolder, this); } DeviceContext.OutputMerger.SetTargets(_gDepthBuffer.DepthView, _gBufferBase.TargetView, _gBufferNormal.TargetView, _gBufferMaps.TargetView); DeviceContext.ClearDepthStencilView(_gDepthBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0); DeviceContext.ClearRenderTargetView(_gBufferBase.TargetView, ColorTransparent); DeviceContext.ClearRenderTargetView(_gBufferNormal.TargetView, ColorTransparent); DeviceContext.ClearRenderTargetView(_gBufferMaps.TargetView, ColorTransparent); DeviceContext.OutputMerger.BlendState = null; }
public void RunFrame() { // clear the render target to a soothing blue context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); context.ClearRenderTargetView(renderTarget, new Color4(0.0f, 0.5f, 1.0f)); var view = Matrix.LookAtLH(camera.Position, camera.LookAtPosition, camera.UpVector); var proj = Matrix.PerspectiveFovLH(DegToRad(45.0f), (float)this.ClientSize.Width / (float)this.ClientSize.Height, 0.1f, 100.0f); ConstantBuffer constantData = new ConstantBuffer { worldMatrix = Matrix.Identity, viewMatrix = Matrix.Transpose(view), projectionMatrix = proj, colour = new Color4(0.5f, 1.0f, 0.0f) }; using (var data = new DataStream(Marshal.SizeOf(constantData), true, true)) { data.Write(constantData); data.Position = 0; context.UpdateSubresource(new DataBox(0, 0, data), constantBuffer, 0); } context.VertexShader.SetConstantBuffer(constantBuffer, 0); context.PixelShader.SetConstantBuffer(constantBuffer, 0); // draw the triangle context.Draw(triangleCount * 3, 0); swapChain.Present(0, PresentFlags.None); }
public void BeginScene(Color4 color) { // Clear the back buffer. DeviceContext.ClearRenderTargetView(RenderTargetView, color); // Clear the depth buffer. DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); }
protected override void DrawPrepare() { base.DrawPrepare(); var highlighted = AmbientShadowHighlight ? (IRenderableObject)CarNode?.AmbientShadowNode : SelectedObject; if (highlighted == null || _outlineBuffer == null) { return; } DeviceContext.ClearDepthStencilView(_outlineDepthBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0); DeviceContext.OutputMerger.SetTargets(_outlineDepthBuffer.DepthView); DeviceContext.Rasterizer.State = DeviceContextHolder.States.DoubleSidedState; highlighted.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.Outline); DeviceContext.ClearRenderTargetView(_outlineBuffer.TargetView, Color.Transparent); DeviceContext.OutputMerger.SetTargets(_outlineBuffer.TargetView); var effect = DeviceContextHolder.GetEffect <EffectPpOutline>(); effect.FxDepthMap.SetResource(_outlineDepthBuffer.View); effect.FxScreenSize.Set(new Vector4(ActualWidth, ActualHeight, 1f / ActualWidth, 1f / ActualHeight)); DeviceContextHolder.PrepareQuad(effect.LayoutPT); effect.TechOutline.DrawAllPasses(DeviceContext, 6); }
public void Render(Action immediateDrall = null) { //process resize if (m_needResize) { DoResizeBuffer(); m_needResize = false; } if (immediateDrall != null) { immediateDrall.Invoke(); } EventPreRender.Invoke(); m_context.ClearDepthStencilView(m_depthcStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); m_context.ClearRenderTargetView(m_renderTargetView, Color.Black); //do render { m_commandBuffer[CommandBufferStage.PreRender].ForEach((x) => { x.Render(this); }); m_commandBuffer[CommandBufferStage.Default].ForEach((x) => { x.Render(this); }); m_commandBuffer[CommandBufferStage.PostRender].ForEach((x) => { x.Render(this); }); } m_swapchain.Present(1, PresentFlags.None); }
internal void OnOpenedCommandList(DeviceContext context) { var depthStencilView = _depthStencilBuffer?.DeviceDepthStencilView; context.OutputMerger.SetRenderTargets( depthStencilView, _renderTargetDescriptor.RenderTarget.DeviceRenderTargetView); switch (_renderTargetDescriptor.LoadAction) { case LoadAction.DontCare: break; case LoadAction.Load: throw new NotSupportedException(); case LoadAction.Clear: context.ClearRenderTargetView( _renderTargetDescriptor.RenderTarget.DeviceRenderTargetView, _renderTargetDescriptor.ClearColor); break; default: throw new InvalidOperationException(); } if (depthStencilView != null) { context.ClearDepthStencilView( depthStencilView, DepthStencilClearFlags.Depth, _depthStencilBuffer.ClearValue, 0); } }
public static void RenderFrame() { if (Update != null) { Update(); } context.ClearRenderTargetView(renderTarget, new Color4(0.17f, 0.47f, 0.79f)); context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); viewMatrix = camera.GetViewMatrix(); SetWVP(Matrix.Identity); if (ActiveModel != null) { ActiveModel.Draw(); } SetWVP(Matrix.Identity); grid.Draw(); if (ActiveEditor != null) { SetWVP(Matrix.Identity); ActiveEditor.DrawUI(); } swapChain.Present(0, PresentFlags.None); }
public override void Render(Action <IGraphicsImmediatelyContext> immediateDrall = null) { if (m_needResize) { DoResizeBuffer(); m_needResize = false; } //clear m_context.ClearDepthStencilView(m_depthcStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); m_context.ClearRenderTargetView(m_renderTargetView, Color.Black); //immediate draw if (immediateDrall != null) { immediateDrall.Invoke(ImmediatelyContext); } //do render //{ // m_commandBuffer[CommandBufferStage.PreRender].ForEach((x) => { x.Render(this); }); // m_commandBuffer[CommandBufferStage.Default].ForEach((x) => { x.Render(this); }); // m_commandBuffer[CommandBufferStage.PostRender].ForEach((x) => { x.Render(this); }); //} m_swapchain.Present(1, PresentFlags.None); }
public void BeginScene(float red, float green, float blue, float alpha) { // Clear the depth buffer. DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1, 0); // Clear the back buffer. DeviceContext.ClearRenderTargetView(_renderTargetView, new Color4(red, green, blue, alpha)); }
public void Prepare(DeviceContext context, Color color, byte stencil, Action prepareMask) { context.ClearRenderTargetView(RenderTargetView, color); context.ClearDepthStencilView(DepthTargetView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, RenderingConstants.DepthClearValue, stencil); SetAsTarget(context); prepareMask(); }
private void DrawShadow(Vector3 from, Vector3?up = null) { DeviceContext.OutputMerger.DepthStencilState = null; DeviceContext.OutputMerger.BlendState = null; DeviceContext.Rasterizer.State = DeviceContextHolder.States.DoubleSidedState; DeviceContext.Rasterizer.SetViewports(_shadowViewport); DeviceContext.ClearDepthStencilView(_shadowBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0); DeviceContext.OutputMerger.SetTargets(_shadowBuffer.DepthView); _shadowCamera.LookAt(Vector3.Normalize(from) * _shadowCamera.FarZValue * 0.8f, Vector3.Zero, up ?? Vector3.UnitY); _shadowCamera.UpdateViewMatrix(); if (HideWheels && !_wheelMode) { var wheelNodes = new[] { "WHEEL_LF", "WHEEL_LR", "WHEEL_RF", "WHEEL_RR", "HUB_LF", "HUB_LR", "HUB_RF", "HUB_RR", "SUSP_LF", "SUSP_LR", "SUSP_RF", "SUSP_RR", }; _scene.Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple, x => !wheelNodes.Contains((x as Kn5RenderableList)?.OriginalNode.Name)); } else { _scene.Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple); } }
private void Draw(float time) { _dx11DeviceContext.ClearRenderTargetView(_renderView, Color); _dx11DeviceContext.ClearDepthStencilView(_depthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); OnDraw?.Invoke(time); _swapChain.Present(0, PresentFlags.None); }
public void BindComponents(DeviceContext deviceContext) { deviceContext.Rasterizer.SetViewport(viewport); // deviceContext.OutputMerger.SetRenderTargets(RenderTargetView); deviceContext.ClearDepthStencilView(DepthMapDsv, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0); deviceContext.ClearRenderTargetView(RenderTargetViews[0], Color.White); }
private void DrawShadow(Vector3 from, Vector3?up = null) { from.Normalize(); _effect.FxLightDir.Set(from); DeviceContext.OutputMerger.BlendState = null; DeviceContext.OutputMerger.DepthStencilState = null; DeviceContext.Rasterizer.SetViewports(_shadowViewport); DeviceContext.ClearDepthStencilView(_shadowBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0); DeviceContext.OutputMerger.SetTargets(_shadowBuffer.DepthView); _shadowCamera.LookAt(from * _shadowCamera.FarZValue * 0.5f, Vector3.Zero, up ?? Vector3.UnitY); _shadowCamera.UpdateViewMatrix(); if (_flattenNodes == null) { _flattenNodes = Flatten(Scene, x => (x as Kn5RenderableDepthOnlyObject)?.OriginalNode.CastShadows != false && IsVisible(x)).OfType <Kn5RenderableDepthOnlyObject>().ToArray(); var states = new[] { _rasterizerStateFrontCull, _rasterizerStateBackCull }; _flattenNodes.ForEach(x => x.SeveralRasterizerStates = states); } for (var i = 0; i < _flattenNodes.Length; i++) { _flattenNodes[i].Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple); } }
public override void RenderScene() { if ((!IsInitialized) || IsDisposed) { return; } _deviceContext.ClearRenderTargetView(_renderTargetView, ClearColor); _deviceContext.ClearDepthStencilView(_depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); foreach (var shape in _shapes) { var SRT = Matrix4x4.CreateScale(shape.Size) * shape.Transform; var model = ToSlimDXMatrix(SRT); if (shape.GetType() == typeof(Box)) { DrawBox(model); } else if (shape.GetType() == typeof(Quad)) { DrawQuad(model); } } _swapChain.Present(0, PresentFlags.None); }
public void Render(DeviceContext deviceContext, Viewport viewport, RenderTargetView renderTargetView, DepthStencilView depthStencilView) { deviceContext.ClearRenderTargetView(renderTargetView, Constants.CLEAR_COLOR); deviceContext.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0x00); var centerDataSpace = mTileManager.TiledDatasetView.CenterDataSpace; var extentDataSpace = mTileManager.TiledDatasetView.ExtentDataSpace; var camera = new Camera( new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0), Matrix.OrthoOffCenterLH( centerDataSpace.X - (extentDataSpace.X / 2f), centerDataSpace.X + (extentDataSpace.X / 2f), centerDataSpace.Y + (extentDataSpace.Y / 2f), centerDataSpace.Y - (extentDataSpace.Y / 2f), 0.1f, 100f)); var datasetExtentDataSpaceX = mTileManager.TiledDatasetDescription.TiledVolumeDescriptions.Get("SourceMap").NumTilesX *Constants.ConstParameters.GetInt("TILE_SIZE_X"); var datasetExtentDataSpaceY = mTileManager.TiledDatasetDescription.TiledVolumeDescriptions.Get("SourceMap").NumTilesY *Constants.ConstParameters.GetInt("TILE_SIZE_Y"); mTileManager.GetTileCache().ToList().ForEach(tileCacheEntry => RenderTileCacheEntry(deviceContext, camera, datasetExtentDataSpaceX, datasetExtentDataSpaceY, tileCacheEntry)); //mTinyTextContext.Print( viewport, "Frame Time: " + FrameTimeString, 10, 10 ); //mTinyTextContext.Print( viewport, "Number of Active Cache Entries: " + mTileManager.GetTileCache().Count, 10, 30 ); //mTinyTextContext.Render(); mStopwatch.Reset(); mStopwatch.Start(); }
protected override void DrawOverride() { base.DrawOverride(); switch (Mode) { case RenderingMode.Result: DeviceContext.ClearDepthStencilView(_temporaryDepthBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); DeviceContext.OutputMerger.SetTargets(_temporaryDepthBuffer.DepthView); DeviceContext.OutputMerger.BlendState = null; Scene.Draw(DeviceContextHolder, Camera, SpecialRenderMode.DeferredTransparentMask); DrawLights(_temporaryBuffer0, _temporaryDepthBuffer.DepthView); if (UseLocalReflections) { DrawReflections(_temporaryBuffer2, BlurLocalReflections ? _temporaryBuffer1 : null, _temporaryBuffer0, _temporaryDepthBuffer.DepthView); } CombineResult(_temporaryBuffer1, _temporaryBuffer0, UseLocalReflections ? _temporaryBuffer2 : null, null, _temporaryDepthBuffer.DepthView); DrawTransparent(); ProcessHdr(_temporaryBuffer0, _temporaryBuffer2, _temporaryBuffer3); FinalStep(_temporaryBuffer0); break; case RenderingMode.WithoutTransparent: DrawLights(_temporaryBuffer0); DrawReflections(_temporaryBuffer2, BlurLocalReflections ? _temporaryBuffer1 : null, _temporaryBuffer0); CombineResult(_temporaryBuffer1, _temporaryBuffer0, _temporaryBuffer2); ProcessHdr(_temporaryBuffer0, _temporaryBuffer1, _temporaryBuffer3); FinalStep(_temporaryBuffer0); break; case RenderingMode.DebugGBuffer: CombineResult(_temporaryBuffer0, null, null); FinalStep(_temporaryBuffer0); return; case RenderingMode.DebugLighting: DrawLights(_temporaryBuffer0); FinalStep(_temporaryBuffer0, _sunShadows.Splits[0].Buffer); break; case RenderingMode.DebugLocalReflections: case RenderingMode.DebugPostEffects: DrawLights(_temporaryBuffer0); DrawReflections(_temporaryBuffer2, BlurLocalReflections ? _temporaryBuffer1 : null, _temporaryBuffer0); CombineResult(_temporaryBuffer1, _temporaryBuffer0, _temporaryBuffer2); FinalStep(_temporaryBuffer1); return; default: throw new ArgumentOutOfRangeException(); } }
private void BeginScene(Color4 givenColour) { // Clear the depth buffer. DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1, 0); // Clear the back buffer. DeviceContext.ClearRenderTargetView(RenderTargetView, givenColour); }
public void ClearDepth(DeviceContext context) { if (!UseDepth) { return; } context.ClearDepthStencilView(DSV, DepthStencilClearFlags.Depth, 0.0f, 0); }
void DrawMesh(Matrix v, Matrix p, RenderTargetView rv, DepthStencilView dv) { _dx11DeviceContext.OutputMerger.SetRenderTargets(dv, rv); _dx11DeviceContext.ClearRenderTargetView(rv, Color); _dx11DeviceContext.ClearDepthStencilView(dv, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); }
public void BindDsvAndSetNullRenderTarget(DeviceContext dc) { dc.Rasterizer.SetViewports(_viewport); dc.OutputMerger.SetTargets(_depthMapDSV, (RenderTargetView)null); dc.ClearDepthStencilView(_depthMapDSV, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); }
public void Clear(DeviceContext context, Color background) { context.ClearDepthStencilView(DSV, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); foreach (var rtv in RTVs) { context.ClearRenderTargetView(rtv, background); } }
public void BindDsvAndSetNullRenderTarget(DeviceContext dc) { dc.Rasterizer.SetViewports(_viewport); dc.OutputMerger.SetTargets(_depthMapDSV, (RenderTargetView)null); dc.ClearDepthStencilView(_depthMapDSV, DepthStencilClearFlags.Depth|DepthStencilClearFlags.Stencil, 1.0f, 0); }
public void ClearRenderTarget(DeviceContext deviceContext, DepthStencilView depthStencilView, Color4 color) { deviceContext.ClearRenderTargetView(_renderTargetView, color); deviceContext.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); return; }
public void Prepare(DeviceContext context, Color color, byte stencil, Action prepareMask) { context.ClearRenderTargetView(AccumTargetView, new Color4(0, 0, 0, 0)); context.ClearRenderTargetView(RevealageTargetView, new Color4(1, 1, 1, 1)); context.ClearDepthStencilView(DepthTargetView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, RenderingConstants.DepthClearValue, stencil); context.OutputMerger.SetTargets(DepthTargetView, AccumTargetView); prepareMask(); }
public void ClearAndSetMainRenderTarget() { deviceContext.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0); deviceContext.ClearRenderTargetView(renderTargetView, Color.OrangeRed); deviceContext.ClearRenderTargetView(objectIdView, Color.FromRgba(uint.MaxValue)); deviceContext.Rasterizer.SetViewport(m_viewport); deviceContext.OutputMerger.SetTargets(depthView, renderTargetView); }
private void Clear(Color4 color) { // Clear the back buffer deviceContext.ClearRenderTargetView(backBufferView, color); // Clear the depth buffer DeviceContext.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); }
public void UpdateShadowMap(Action renderScene) { context.ClearState(); context.ClearDepthStencilView(shadowMapDSV, DepthStencilClearFlags.Depth, 1, 0); context.Rasterizer.SetViewports(new Viewport(0, 0, shadowMapSize, shadowMapSize)); context.OutputMerger.SetTargets(shadowMapDSV); renderScene(); }
public void Render( DeviceContext deviceContext, Viewport viewport, RenderTargetView renderTargetView, DepthStencilView depthStencilView ) { deviceContext.ClearRenderTargetView( renderTargetView, Constants.CLEAR_COLOR ); deviceContext.ClearDepthStencilView( depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0x00 ); //mTinyTextContext.Print( viewport, "Frame Time: " + FrameTimeString, 10, 10 ); //mTinyTextContext.Render(); mStopwatch.Reset(); mStopwatch.Start(); }
public void ClearRenderTarget(DeviceContext context, DepthStencilView depthStencilView, float red, float green, float blue, float alpha) { // Setup the color the buffer to. var color = new Color4(red, green, blue, alpha); // Clear the back buffer. context.ClearRenderTargetView(RenderTargetView, color); // Clear the depth buffer. context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); }
/// <summary> /// Clears the instance /// </summary> /// <param name="context"></param> public virtual void Clear(DeviceContext context) { if (!IsDepthStencilUsed || (!DepthStencilClearSettings.IsClearDepth && !DepthStencilClearSettings.IsClearStencil)) return; var dsFlags = (DepthStencilClearFlags) 0; if (DepthStencilClearSettings.IsClearDepth) dsFlags |= DepthStencilClearFlags.Depth; if (DepthStencilClearSettings.IsClearStencil) dsFlags |= DepthStencilClearFlags.Stencil; context.ClearDepthStencilView(DepthStencilView, dsFlags, DepthStencilClearSettings.DepthClearValue, DepthStencilClearSettings.StencilClearValue); }
public void Clear(DeviceContext context, Color4 color, bool depth = false) { for (int i = 0; i < m_NumRTs; ++i) { context.ClearRenderTargetView(m_RenderTargets[i].m_RenderTargetView, color); } if (depth && m_DepthStencil.m_DepthStencilView != null) { context.ClearDepthStencilView(m_DepthStencil.m_DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); } }
public static void RenderCubemap(DeviceContext context, TextureObject targetTexture, TextureObject targetDepth, SimpleSceneWrapper sceneWrapper, Vector3 position, float range, bool depthOnly = false, Color4 clearColor = new Color4()) { //using (new GpuProfilePoint(context, "CubemapRendering")) { // some hardcoded near plane Matrix projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 2.0f, 1.0f, 0.05f, range); ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.DepthCompare); // set the shaders context.VertexShader.Set(ShaderManager.GetVertexShader("VertexScene")); context.PixelShader.Set(depthOnly ? null : ShaderManager.GetPixelShader("PixelSceneSimple")); dynamic cvpb = m_CurrentViewportBuffer; for (int i = 0; i < 6; ++i) { Vector3 lookAt = new Vector3(); Vector3 upVec = new Vector3(); switch (i) { case 0: lookAt = new Vector3(1.0f, 0.0f, 0.0f); upVec = new Vector3(0.0f, 1.0f, 0.0f); break; case 1: lookAt = new Vector3(-1.0f, 0.0f, 0.0f); upVec = new Vector3(0.0f, 1.0f, 0.0f); break; case 2: lookAt = new Vector3(0.0f, 1.0f, 0.0f); upVec = new Vector3(0.0f, 0.0f, -1.0f); break; case 3: lookAt = new Vector3(0.0f, -1.0f, 0.0f); upVec = new Vector3(0.0f, 0.0f, 1.0f); break; case 4: lookAt = new Vector3(0.0f, 0.0f, 1.0f); upVec = new Vector3(0.0f, 1.0f, 0.0f); break; case 5: lookAt = new Vector3(0.0f, 0.0f, -1.0f); upVec = new Vector3(0.0f, 1.0f, 0.0f); break; } Matrix viewMatrix = Matrix.LookAtLH(position, position + lookAt, upVec); cvpb.g_ProjMatrix = projectionMatrix; cvpb.g_ViewMatrix = viewMatrix; cvpb.g_ViewProjMatrix = viewMatrix * projectionMatrix; { context.ClearRenderTargetView(targetTexture.m_ArrayRenderTargetViews[i], clearColor); context.ClearDepthStencilView(targetDepth.m_ArrayDepthStencilViews[i], DepthStencilClearFlags.Depth, 1.0f, 0); RenderTargetSet.BindTextureAsRenderTarget(context, targetTexture.m_ArrayRenderTargetViews[i], targetDepth.m_ArrayDepthStencilViews[i], targetTexture.m_Width, targetTexture.m_Height); m_CurrentViewportBuffer.CompileAndBind(context); // render triangles sceneWrapper.Render(context); RenderTargetSet.BindNull(context); } } ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.NoDepth); } }
/// <summary> /// Enable the rendering in this viewport /// </summary> public void EnableViewport(DeviceContext devCont) { // Set the render target to the specific viewport devCont.OutputMerger.SetTargets( m_DepthStencilView, m_RenderTarget ); /// Clear or fill the Render target with a single color devCont.ClearRenderTargetView( m_RenderTarget, new Color4( 0.0f, 0.0f, 0.0f, 1.0f ) ); //m_RenderTarget, new Color4( 0.0f, 0.125f, 0.3f, 1.0f ) ); /// clear the depth buffer to 1.0 (max depth) devCont.ClearDepthStencilView( m_DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0 ); /// Set the selected camera to the /// camera of the selected viewport Engine.g_RenderCamera = m_Camera; /// Apply the viewport the rasterizer /// (the thing that actually draws the triangle) devCont.Rasterizer.SetViewport( m_Viewport.X, m_Viewport.Y, m_Viewport.Width, m_Viewport.Height, m_Viewport.MinZ, m_Viewport.MaxZ); if ( m_RasterizerState.Description.FillMode != Settings.FillMode || m_RasterizerState.Description.CullMode != Settings.CullMode) { m_RasterizerStateDesc = new RasterizerStateDescription(); m_RasterizerStateDesc.CullMode = Settings.CullMode; m_RasterizerStateDesc.FillMode = Settings.FillMode; m_RasterizerStateDesc.IsDepthClipEnabled = true; m_RasterizerStateDesc.IsScissorEnabled = false; m_RasterizerStateDesc.IsMultisampleEnabled = false; m_RasterizerStateDesc.IsAntialiasedLineEnabled = false; m_RasterizerStateDesc.SlopeScaledDepthBias = 0.0f; m_RasterizerStateDesc.DepthBiasClamp = 0.0f; m_RasterizerStateDesc.DepthBias = 0; m_RasterizerState = new RasterizerState( Engine.g_device, m_RasterizerStateDesc ); } /// set the rasterizer state devCont.Rasterizer.State = m_RasterizerState; }
public void Draw(float TimeMili, Device device, DeviceContext context) { if (RebderCube) { RebderCube = false; SkyBox.RenderCubemap(); } Random R = new Random(2); for (int i = 0; i < 0; i+=2) { DVector3 t = new DVector3(R.NextDouble(-500, 500), R.NextDouble(-500, 500), R.NextDouble(-500, 500)); LensBatching.DrawLens(t, new Vector2(5, 5), new Vector2(0, 0), new Vector2(1, 1), new Vector4(1, 0, 0, 1), TC1); t = new DVector3(R.NextDouble(-500, 500), R.NextDouble(-500, 500), R.NextDouble(-500, 500)); LensBatching.DrawLens(t, new Vector2(5, 5), new Vector2(0, 0), new Vector2(1, 1), new Vector4(0, 0, 1, 1), TC2); } LensBatching.DrawLens(Camera.position + Conversion.ToDoubleVector(-LightDirection)*Camera.farClip*0.95f, new Vector2(1000, 1000), new Vector2(0, 0), new Vector2(1, 1), new Vector4(1, 0, 0, 1), TC1); KDtree KDT = new KDtree(20, AllObjects); List<GameObject> InCam = KDT.GetBodyInCamera(Camera.position, Camera.LcameraFrustum); DebugDraw.ResetLine(); //Depth device.ImmediateContext.OutputMerger.SetTargets(DepthMapStencilView, DepthTarget); device.ImmediateContext.ClearDepthStencilView(DepthMapStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); context.ClearRenderTargetView(DepthTarget, new Color4(1.0f, 0.0f, 0.0f, 1.0f)); for (int i = 0; i < InCam.Count; i++) if (InCam[i] != null) InCam[i].DrawDepth(device, Camera); PSSMsHelper.RenderAllSplits(device, Camera, Conversion.ToDoubleVector(LightDirection), KDT, InCam); // DrawHelper.OcclusionTest(device, Camera, DepthSRV); // context.Rasterizer.SetViewports(Program.viewport); context.OutputMerger.SetTargets(DepthStencilView, HDRTarget); context.ClearRenderTargetView(HDRTarget, new Color4(0.5f, 0.5f, 1.0f, 1.0f)); context.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); //DebugDraw.AddLine(new DebugLine(KDT.Root.AA, KDT.Root.BB, new Vector3(1, 0, 0))); //DebugDraw.DrawAABB(KDT.Root.AA, KDT.Root.BB, new Vector3(1, 0, 0)); //DebugDraw.DrawKDTree(KDT, new Vector3(1, 0, 0)); //DebugDraw.DrawLocator(new DVector3(50, 50, 0), 5, new Vector3(0, 1, 0)); SkyBox.Draw(TimeMili, device, context, Camera); /* for (int i = 0; i < InCam.Count; i++) if (InCam[i] != null) InCam[i].Draw(device, Camera, Light, LightDirection); */ PSSMsHelper.RenderObj(TimeMili, device, Camera, LightDirection, Light.Color, InCam); for (int i = 0; i < InCam.Count; i++) if (InCam[i] != null) InCam[i].DrawEffects(device, Camera); LensBatching.BatchingDrawLens(device, Camera, DepthSRV); DebugDraw.Draw(device, Camera); /* foreach (GSSprite TS_ in TS) { TS_.Render(device, Camera, DepthSRV); } */ //context.OutputMerger.SetTargets(renderTarget); //HDRSRV //DepthSRV QuadScreen.FinalRender(device, TimeMili, context, HDRSRV, DepthSRV, renderTarget); /* Int64 TStart = Program.HiTimer.Value; Int64 TStop = Program.HiTimer.Value; float Time = Program.HiTimer.Tick2Mili(TStop - TStart); Program.form.Text = Time.ToString();*/ }
public void BindDsvAndSetNullRenderTarget(DeviceContext context) { context.Rasterizer.SetViewports(new RawViewportF[] { _viewport }); context.OutputMerger.SetTargets(_depthMapDSV, (RenderTargetView)null); context.ClearDepthStencilView(_depthMapDSV, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); }
public void Render(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Light light) { Light newLight = new Light(light.Direction, light.Color, new Vector4(1), light.SpecularPower, light.SpecularColor); _skydome.Render(deviceContext); _renderer.LightShader.Render(deviceContext, _skydome.IndexCount, Matrix.Scaling(10000) * Matrix.RotationY(MathUtil.PiOverTwo-WaveTranslation.X/8), viewMatrix, projectionMatrix, _skydome.Texture, newLight, _renderer.Camera); deviceContext.ClearDepthStencilView(_renderer.DirectX.RenderToTextureDepthStencilView, DepthStencilClearFlags.Depth, 1, 0); _refractionTexture.SetRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView); _refractionTexture.ClearRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView, 0.0f, 0.0f, 0.0f, 1.0f); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf<VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, viewMatrix, projectionMatrix, light, _terrainTextures, _refractionClippingPlane); deviceContext.ClearDepthStencilView(_renderer.DirectX.RenderToTextureDepthStencilView, DepthStencilClearFlags.Depth, 1, 0); _reflectionTexture.SetRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView); _reflectionTexture.ClearRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView, 0.0f, 0.0f, 0.0f, 1.0f); _skydome.Render(deviceContext); _renderer.LightShader.Render(deviceContext, _skydome.IndexCount, Matrix.Scaling(10000) * Matrix.RotationY(MathUtil.PiOverTwo - WaveTranslation.X/8), viewMatrix, projectionMatrix, _skydome.Texture, newLight, _renderer.Camera); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf<VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, _renderer.Camera.ReflectionMatrix, projectionMatrix, light, _terrainTextures, _reflectionClippingPlane); _renderer.DirectX.SetBackBufferAsRenderTarget(); //Render water deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(WaterVertexBuffer, Utilities.SizeOf<VertexDefinition.PositionTexture>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(WaterIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; WaterShader.Render(deviceContext, WaterIndexCount, worldMatrix, viewMatrix, projectionMatrix, _renderer.Camera.ReflectionMatrix, _reflectionTexture.ShaderResourceView, _refractionTexture.ShaderResourceView, _bumpMap.TextureResource, WaveTranslation, _renderer.Camera.Position); //Render terrain deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf<VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, viewMatrix, projectionMatrix, light, _terrainTextures, _noClippingPlane); _bitmap.Render(deviceContext); _renderer.TextureShader.Render(deviceContext, _bitmap.IndexCount, Matrix.Identity, _renderer.Camera.UiMatrix, _renderer.DirectX.OrthoMatrix, _refractionTexture.ShaderResourceView); _bitmap2.Render(deviceContext); _renderer.TextureShader.Render(deviceContext, _bitmap.IndexCount, Matrix.Identity, _renderer.Camera.UiMatrix, _renderer.DirectX.OrthoMatrix, _reflectionTexture.ShaderResourceView); }
public void ClearRenderTarget(DeviceContext context, DepthStencilView depthStencilView, float red, float green, float blue, float alpha) { context.ClearRenderTargetView(_renderTargetView, new Color4(red, green, blue, alpha)); context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); }
public void Render(RenderTargetView renderTargetView, DeviceContext context, SurfacePass pass) { // TODO: generate sky envmap here, with custom params pass.Pass(context, @" struct PS_IN { float4 pos : SV_POSITION; float2 tex : TEXCOORD; }; float3 main(PS_IN input) : SV_Target { float phi = 2 * 3.14159265 * input.tex.x; float theta = 3.14159265 * input.tex.y; float3 p = float3(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi)); float brightness = 500; if (p.y < 0) return lerp(float3(1, 1, 1), float3(0, 0, 0), -p.y) * brightness; /* TEMPORARY */ float sunBrightness = (dot(p, normalize(float3(-0.5f, 0.8f, 0.9f))) > 0.9995f) ? 1 : 0; return lerp(float3(1, 1, 1), float3(0.7f, 0.7f, 1), p.y) * brightness + sunBrightness * 50000; } ", skyEnvMap.Dimensions, skyEnvMap.RTV, null, null); context.OutputMerger.SetRenderTargets((RenderTargetView)null); context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); context.ClearRenderTargetView(renderTargetView, new Color4(0.5f, 0, 1, 1)); context.Rasterizer.State = rasterizerState; context.OutputMerger.DepthStencilState = depthStencilState; context.OutputMerger.SetTargets(depthStencilView, renderTargetView); context.Rasterizer.SetViewports(new[] { new ViewportF(0, 0, RenderDimensions.Width, RenderDimensions.Height) }); context.Rasterizer.SetScissorRectangles(new[] { new SharpDX.Rectangle(0, 0, RenderDimensions.Width, RenderDimensions.Height) }); context.VertexShader.Set(vertexShader); context.InputAssembler.InputLayout = inputLayout; context.PixelShader.SetShaderResource(0, skyEnvMap.SRV); context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; { DataStream cameraStream; context.MapSubresource(cameraBuffer, MapMode.WriteDiscard, MapFlags.None, out cameraStream); camera.WriteTo(cameraStream); context.UnmapSubresource(cameraBuffer, 0); cameraStream.Dispose(); } context.VertexShader.SetConstantBuffer(0, cameraBuffer); context.PixelShader.SetConstantBuffer(0, cameraBuffer); foreach (Model model in models.Values) model.Render(context, camera, materials, proxy); }
public void SetRenderTarget(DeviceContext context, DepthStencilView depthStencilView) { // Bind the render target view and depth stencil buffer to the output pipeline. context.OutputMerger.SetTargets(depthStencilView, texRenderTargetView); // Setup the color the buffer to. var color = new Color4(0.0f, 0.0f, 1.0f, 1.0f); // Clear the render to texture buffer. context.ClearRenderTargetView(texRenderTargetView, color); // Clear the depth buffer. context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); }
public void Render( DeviceContext deviceContext, Viewport viewport, RenderTargetView renderTargetView, DepthStencilView depthStencilView ) { deviceContext.ClearRenderTargetView( renderTargetView, Constants.CLEAR_COLOR ); deviceContext.ClearDepthStencilView( depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0x00 ); var centerDataSpace = mTileManager.TiledDatasetView.CenterDataSpace; var extentDataSpace = mTileManager.TiledDatasetView.ExtentDataSpace; var camera = new Camera( new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 1, 0 ), Matrix.OrthoOffCenterLH( centerDataSpace.X - ( extentDataSpace.X / 2f ), centerDataSpace.X + ( extentDataSpace.X / 2f ), centerDataSpace.Y + ( extentDataSpace.Y / 2f ), centerDataSpace.Y - ( extentDataSpace.Y / 2f ), 0.1f, 100f ) ); var datasetExtentDataSpaceX = mTileManager.TiledDatasetDescription.TiledVolumeDescriptions.Get( "SourceMap" ).NumTilesX * Constants.ConstParameters.GetInt( "TILE_SIZE_X" ); var datasetExtentDataSpaceY = mTileManager.TiledDatasetDescription.TiledVolumeDescriptions.Get( "SourceMap" ).NumTilesY * Constants.ConstParameters.GetInt( "TILE_SIZE_Y" ); mTileManager.GetTileCache().ToList().ForEach( tileCacheEntry => RenderTileCacheEntry( deviceContext, camera, datasetExtentDataSpaceX, datasetExtentDataSpaceY, tileCacheEntry, viewport ) ); //mTinyTextContext.Print( viewport, "Frame Time: " + FrameTimeString, 10, 10 ); //mTinyTextContext.Print( viewport, "Number of Active Cache Entries: " + mTileManager.GetTileCache().Count, 10, 30 ); //mTinyTextContext.Render(); mStopwatch.Reset(); mStopwatch.Start(); }