public void OnInitialize(DeviceContextHolder holder) { _effect = holder.GetEffect <EffectPpHdr>(); _blurHelper = holder.GetHelper <BlurHelper>(); _textures = Enumerable.Range(0, DownsamplerAdaptationCycles) .Select(x => TargetResourceTexture.Create(Format.R16G16B16A16_Float)) .ToArray(); _averateColor = Enumerable.Range(0, 2).Select(x => { var t = TargetResourceTexture.Create(Format.R16G16B16A16_Float); t.Resize(holder, 1, 1, null); return(t); }).ToArray(); _newAverageColor = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _newAverageColor.Resize(holder, 1, 1, null); _bloomTexture = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _tempTexture = TargetResourceTexture.Create(Format.R16G16B16A16_Float); }
private bool ColorGradingPass(ShaderResourceView input, RenderTargetView output, Viewport viewport) { if (ColorGradingData == null) { return(false); } if (!_colorGradingSet) { _colorGradingSet = true; try { LoadColorGradingData(); } catch (Exception e) { AcToolsLogging.Write(e); } } if (_colorGradingView == null) { return(false); } if (_hdr == null) { _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>(); } DeviceContext.Rasterizer.SetViewports(viewport); DeviceContext.OutputMerger.SetTargets(output); _hdr.FxInputMap.SetResource(input); _hdr.FxColorGradingMap.SetResource(_colorGradingView); _hdr.TechColorGrading.DrawAllPasses(DeviceContext, 6); return(true); }
protected bool HdrPass(ShaderResourceView input, RenderTargetView output, Viewport viewport) { if (UseLensFlares) { // prepare effects if (_lensFlares == null) { _lensFlares = DeviceContextHolder.GetEffect <EffectPpLensFlares>(); } if (_hdr == null) { _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>(); } if (_blur == null) { _blur = DeviceContextHolder.GetHelper <BlurHelper>(); } // filter bright areas by high threshold to downscaled buffer #1 DeviceContext.Rasterizer.SetViewports(_bufferH1.Viewport); DeviceContext.OutputMerger.SetTargets(_bufferH1.TargetView); DeviceContext.ClearRenderTargetView(_bufferH1.TargetView, ColorTransparent); DeviceContextHolder.PrepareQuad(_hdr.LayoutPT); _hdr.FxInputMap.SetResource(input); _hdr.TechBloomHighThreshold.DrawAllPasses(DeviceContext, 6); DeviceContext.Rasterizer.SetViewports(_bufferH2.Viewport); DeviceContext.OutputMerger.SetTargets(_bufferH2.TargetView); DeviceContext.ClearRenderTargetView(_bufferH2.TargetView, ColorTransparent); DeviceContextHolder.PrepareQuad(_lensFlares.LayoutPT); _lensFlares.FxInputMap.SetResource(_bufferH1.View); _lensFlares.TechGhosts.DrawAllPasses(DeviceContext, 6); // blur bright areas from buffer #1 to itself using downscaled buffer #3 as a temporary one _blur.Blur(DeviceContextHolder, _bufferH2, _bufferH1, 2f, 2); // combine original buffer and buffer #1 with blurred bright areas to buffer #2 DeviceContext.Rasterizer.SetViewports(viewport); DeviceContext.OutputMerger.SetTargets(output); _hdr.FxInputMap.SetResource(input); _hdr.FxBloomMap.SetResource(_bufferH2.View); GetHdrTechnique().DrawAllPasses(DeviceContext, 6); return(true); } if (UseBloom) { // prepare effects if (_hdr == null) { _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>(); } if (_blur == null) { _blur = DeviceContextHolder.GetHelper <BlurHelper>(); } // filter bright areas by high threshold to downscaled buffer #1 DeviceContext.Rasterizer.SetViewports(_bufferH1.Viewport); DeviceContext.OutputMerger.SetTargets(_bufferH1.TargetView); DeviceContext.ClearRenderTargetView(_bufferH1.TargetView, ColorTransparent); DeviceContextHolder.PrepareQuad(_hdr.LayoutPT); _hdr.FxInputMap.SetResource(input); _hdr.TechBloomHighThreshold.DrawAllPasses(DeviceContext, 6); // blur bright areas from buffer #1 to itself using downscaled buffer #3 as a temporary one _blur.Blur(DeviceContextHolder, _bufferH1, _bufferH2, 0.5f * BloomRadiusMultiplier, 2); // combine original buffer and buffer #1 with blurred bright areas to buffer #2 DeviceContext.Rasterizer.SetViewports(viewport); DeviceContext.OutputMerger.SetTargets(output); _hdr.FxInputMap.SetResource(input); _hdr.FxBloomMap.SetResource(_bufferH1.View); GetHdrTechnique().DrawAllPasses(DeviceContext, 6); return(true); } if (ToneMapping != ToneMappingFn.None) { if (_hdr == null) { _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>(); } DeviceContext.Rasterizer.SetViewports(viewport); DeviceContext.OutputMerger.SetTargets(output); DeviceContextHolder.PrepareQuad(_hdr.LayoutPT); _hdr.FxInputMap.SetResource(input); _hdr.FxBloomMap.SetResource(null); GetHdrTechnique().DrawAllPasses(DeviceContext, 6); return(true); } return(false); }