public void SetToneMappingParams(float mg, float wl, float adapt) { var t = new CommonStructs.ConstBufferPostProcessStruct() { MiddleGrey = mg, LumWhiteSqr = (wl * mg) * (wl * mg), }; AdaptationPercent = adapt; D3DUtils.WriteToDynamicBuffer(GetContext, PostProcessConstantBuffer, t); }
private void DownSampling() { DownScaleConstStruct constData = new DownScaleConstStruct() { ResX = (uint)(GetDisplay.Width / 4), ResY = (uint)(GetDisplay.Height / 4), Domain = (uint)((GetDisplay.Width * GetDisplay.Height) / 16), GroupSize = (uint)((GetDisplay.Width * GetDisplay.Height) / (16 * 1024)), Adaptation = Math.Min(RenderBackend.EngineRef.Time.DeltaTime / AdaptationPercent, 0.9999f), }; D3DUtils.WriteToDynamicBuffer(GetContext, DownScaleConstantsBuffer, constData); SetComputeShader(DownsamplingFirsPassCSName); GetContext.ComputeShader.SetShaderResource(0, HDRTarget.ResourceView); GetContext.ComputeShader.SetUnorderedAccessView(0, CSLuminanceUAV); if (DwnSmplPrev) { GetContext.ComputeShader.SetShaderResource(1, CSAvgLuminanceSRV); } else { GetContext.ComputeShader.SetShaderResource(1, CSPrevAvgLuminanceSRV); } GetContext.Dispatch((GetDisplay.Width * GetDisplay.Height) / (16 * 1024), 1, 1); GetContext.ComputeShader.SetShaderResource(0, null); GetContext.ComputeShader.SetUnorderedAccessView(0, null); GetContext.ComputeShader.SetShaderResource(2, CSLuminanceSRV); if (DwnSmplPrev) { GetContext.ComputeShader.SetUnorderedAccessView(0, CSPrevAvgLuminanceUAV); } else { GetContext.ComputeShader.SetUnorderedAccessView(0, CSAvgLuminanceUAV); } SetComputeShader(DownsamplingSecondPassCSName); GetContext.Dispatch(1, 1, 1); GetContext.ComputeShader.SetShaderResource(1, null); GetContext.ComputeShader.SetShaderResource(2, null); GetContext.ComputeShader.SetUnorderedAccessView(0, null); DwnSmplPrev = !DwnSmplPrev; }
private void ForwardPass(StandardFrameData frameData) { CurrentPass = Pass.Forward; if (frameData.PerCameraLightsList[0].Count == 0) { if (EnabledHDR) { GetContext.OutputMerger.SetRenderTargets(ReadonlyDepthStencilView, HDRTarget.View); } else { GetContext.OutputMerger.SetRenderTargets(ReadonlyDepthStencilView, GetDisplay.RenderTargetViewRef); } } SetDepthStencilState(DepthStencilStates.GreaterAndDisableWrite); SetBlendState(BlendStates.AlphaEnabledBlending); SetInputLayout(GetSharedItems.StandardInputLayout); SetVertexShader("CommonVS"); string MaterialName = ""; StandardFrameData.RendererData rendererData; for (int i = FirstTranslucentRendererIndex; i < frameData.PerCameraRenderersList[0].Count; i++) { rendererData = frameData.RenderersList[frameData.PerCameraRenderersList[0][i]]; SetMesh(rendererData.MeshName); if (MaterialName != rendererData.MaterialName) { MaterialName = rendererData.MaterialName; SetMaterial(MaterialName, true); } m_PerObjectConstantBufferValue = new CommonStructs.ConstBufferPerObjectDefferedStruct() { World = rendererData.TransformMatrix, WorldInverse = Matrix.Transpose(Matrix.Invert(rendererData.TransformMatrix)), }; D3DUtils.WriteToDynamicBuffer(GetContext, PerObjectConstantBuffer, m_PerObjectConstantBufferValue); DX_DrawIndexed(m_CachedMesh.IndexCount, 0, 0); } }