public void Draw(DeviceContextHolder holder, ShaderResourceView view, RenderTargetView target, TargetResourceTexture temporaryEdges, TargetResourceTexture temporaryBlending) { holder.PrepareQuad(_effect.LayoutPT); holder.DeviceContext.OutputMerger.BlendState = null; // edges holder.DeviceContext.OutputMerger.SetTargets(temporaryEdges.TargetView); holder.DeviceContext.ClearRenderTargetView(temporaryEdges.TargetView, new Color4(0f, 0f, 0f, 0f)); _effect.FxScreenSizeSpec.Set(new Vector4(1f / holder.Width, 1f / holder.Height, holder.Width, holder.Height)); _effect.FxInputMap.SetResource(view); _effect.TechSmaa.DrawAllPasses(holder.DeviceContext, 6); // blending holder.DeviceContext.OutputMerger.SetTargets(temporaryBlending.TargetView); holder.DeviceContext.ClearRenderTargetView(temporaryBlending.TargetView, new Color4(0f, 0f, 0f, 0f)); _effect.FxEdgesMap.SetResource(temporaryEdges.View); _effect.FxAreaTexMap.SetResource(_areasTexMap); _effect.FxSearchTexMap.SetResource(_searchTexMap); _effect.TechSmaaB.DrawAllPasses(holder.DeviceContext, 6); // final part holder.DeviceContext.OutputMerger.SetTargets(target); _effect.FxBlendMap.SetResource(temporaryBlending.View); _effect.TechSmaaN.DrawAllPasses(holder.DeviceContext, 6); }
public void Draw(DeviceContextHolder holder, ShaderResourceView view, RenderTargetView target, TargetResourceTexture temporaryLuma) { holder.PrepareQuad(_effect.LayoutPT); holder.DeviceContext.OutputMerger.SetTargets(temporaryLuma.TargetView); _effect.FxInputMap.SetResource(view); _effect.TechLuma.DrawAllPasses(holder.DeviceContext, 6); holder.DeviceContext.OutputMerger.SetTargets(target); _effect.FxScreenSize.Set(new Vector4(holder.Width, holder.Height, 1f / holder.Width, 1f / holder.Height)); _effect.FxInputMap.SetResource(temporaryLuma.View); _effect.TechFxaa.DrawAllPasses(holder.DeviceContext, 6); }
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); return t; }).ToArray(); _newAverageColor = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _newAverageColor.Resize(holder, 1, 1); _bloomTexture = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _tempTexture = TargetResourceTexture.Create(Format.R16G16B16A16_Float); }
protected override void InitializeInner() { _deferredLighting = DeviceContextHolder.GetEffect<EffectDeferredLight>(); _deferredResult = DeviceContextHolder.GetEffect<EffectDeferredResult>(); _ppBasic = DeviceContextHolder.GetEffect<EffectPpBasic>(); _gDepthBuffer = TargetResourceDepthTexture.Create(); _gBufferBase = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _gBufferNormal = TargetResourceTexture.Create(Format.R32G32B32A32_Float); _gBufferMaps = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm); _temporaryDepthBuffer = TargetResourceDepthTexture.Create(); _temporaryBuffer0 = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _temporaryBuffer1 = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _temporaryBuffer2 = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _temporaryBuffer3 = TargetResourceTexture.Create(Format.R16G16B16A16_Float); _outputBuffer = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm); _reflectionCubemap = new ReflectionCubemap(1024); _reflectionCubemap.Initialize(DeviceContextHolder); _sunShadows = new ShadowsDirectional(2048); _sunShadows.Initialize(DeviceContextHolder); }
public void Blur(DeviceContextHolder holder, TargetResourceTexture source, TargetResourceTexture temporary, float power = 1f, int iterations = 1, TargetResourceTexture target = null) { for (var i = 0; i < iterations; i++) { holder.DeviceContext.OutputMerger.SetTargets(temporary.TargetView); BlurHorizontally(holder, (i == 0 ? null : target?.View) ?? source.View, power); holder.DeviceContext.OutputMerger.SetTargets(target?.TargetView ?? source.TargetView); BlurVertically(holder, temporary.View, power); } }
protected override void InitializeInner() { _materialsProvider = CreateMaterialsProvider(); DeviceContextHolder.Set(_materialsProvider); _materialsProvider.SetKn5(_kn5); RootNode = (RenderableList)Kn5Converter.Convert(_kn5.RootNode, DeviceContextHolder); _buffer0 = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm); _buffer1 = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm); }
protected void FinalStep(TargetResourceTexture source, TargetResourceDepthTexture depth, float sizeMultipler = 0.25f) { DeviceContext.OutputMerger.SetTargets(_outputBuffer.TargetView); DeviceContext.ClearRenderTargetView(_outputBuffer.TargetView, ColorTransparent); DeviceContextHolder.QuadBuffers.Prepare(DeviceContext, _ppBasic.LayoutPT); _ppBasic.FxScreenSize.Set(new Vector4(Width, Height, 1f / Width, 1f / Height)); _ppBasic.FxSizeMultipler.Set(sizeMultipler); _ppBasic.FxInputMap.SetResource(source.View); _ppBasic.FxDepthMap.SetResource(depth.View); _ppBasic.TechDepth.DrawAllPasses(DeviceContext, 6); }
protected void FinalStep(TargetResourceTexture source) { DeviceContext.ClearRenderTargetView(_outputBuffer.TargetView, ColorTransparent); if (!UseFxaa) { DeviceContextHolder.GetHelper<CopyHelper>().Draw(DeviceContextHolder, source.View, _outputBuffer.TargetView); return; } if (UseExperimentalSmaa) { DeviceContextHolder.GetHelper<SmaaHelper>().Draw(DeviceContextHolder, source.View, _outputBuffer.TargetView, _gBufferBase, _temporaryBuffer3); } else if (UseExperimentalFxaa) { DeviceContextHolder.GetHelper<Fxaa311Helper>().Draw(DeviceContextHolder, source.View, _outputBuffer.TargetView, _gBufferMaps); } else { DeviceContextHolder.GetHelper<FxaaHelper>().Draw(DeviceContextHolder, source.View, _outputBuffer.TargetView); } }
private void ProcessHdr(TargetResourceTexture target, TargetResourceTexture source, TargetResourceTexture temporary) { switch (Mode) { case RenderingMode.DebugGBuffer: case RenderingMode.DebugPostEffects: case RenderingMode.DebugLocalReflections: return; } DeviceContext.OutputMerger.SetTargets(target.TargetView); DeviceContext.ClearRenderTargetView(target.TargetView, ColorTransparent); DeviceContext.OutputMerger.BlendState = null; DeviceContextHolder.GetHelper<HdrHelper>().Draw(DeviceContextHolder, source.View, temporary); }
private void CombineResult(TargetResourceTexture target, TargetResourceTexture light, TargetResourceTexture reflection, TargetResourceTexture bottomLayer = null, DepthStencilView limitedBy = null) { DeviceContextHolder.QuadBuffers.Prepare(DeviceContext, _deferredResult.LayoutPT); DeviceContext.OutputMerger.BlendState = null; if (limitedBy == null) { DeviceContext.OutputMerger.SetTargets(target.TargetView); } else { DeviceContext.OutputMerger.SetTargets(limitedBy, target.TargetView); DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.GreaterReadOnlyDepthState; } DeviceContext.ClearRenderTargetView(target.TargetView, ColorTransparent); _deferredResult.FxWorldViewProjInv.SetMatrix(Camera.ViewProjInvert); _deferredResult.FxScreenSize.Set(new Vector4(Width, Height, 1f / Width, 1f / Height)); _deferredResult.FxBaseMap.SetResource(_gBufferBase.View); _deferredResult.FxNormalMap.SetResource(_gBufferNormal.View); _deferredResult.FxMapsMap.SetResource(_gBufferMaps.View); _deferredResult.FxDepthMap.SetResource(_gDepthBuffer.View); _deferredResult.FxEyePosW.Set(Camera.Position); _deferredResult.FxLightMap.SetResource(light?.View); _deferredResult.FxLocalReflectionMap.SetResource(reflection?.View); _deferredResult.FxBottomLayerMap.SetResource(bottomLayer?.View); _deferredResult.FxReflectionCubemap.SetResource(_reflectionCubemap.View); EffectTechnique tech; switch (Mode) { case RenderingMode.DebugGBuffer: tech = _deferredResult.TechDebug; break; case RenderingMode.DebugPostEffects: tech = _deferredResult.TechDebugPost; break; case RenderingMode.DebugLighting: tech = _deferredResult.TechDebugLighting; break; case RenderingMode.DebugLocalReflections: tech = _deferredResult.TechDebugLocalReflections; break; case RenderingMode.Result: case RenderingMode.WithoutTransparent: tech = _deferredResult.TechCombine0; break; default: return; } tech.DrawAllPasses(DeviceContext, 6); if (limitedBy != null) DeviceContext.OutputMerger.DepthStencilState = null; }
private void DrawReflections(TargetResourceTexture target, TargetResourceTexture temporary = null, TargetResourceTexture light = null, DepthStencilView limitedBy = null) { var sslr = DeviceContextHolder.GetHelper<SslrHelper>(); DeviceContextHolder.QuadBuffers.Prepare(DeviceContext, sslr.Effect.LayoutPT); DeviceContext.OutputMerger.BlendState = null; if (limitedBy == null) DeviceContext.OutputMerger.SetTargets(target.TargetView); else { DeviceContext.OutputMerger.SetTargets(limitedBy, target.TargetView); DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.GreaterReadOnlyDepthState; } // camera position & matrix sslr.Effect.FxWorldViewProj.SetMatrix(Camera.ViewProj); sslr.Effect.FxWorldViewProjInv.SetMatrix(Camera.ViewProjInvert); sslr.Effect.FxEyePosW.Set(Camera.Position); // g-buffer sslr.Effect.FxBaseMap.SetResource(_gBufferBase.View); sslr.Effect.FxNormalMap.SetResource(_gBufferNormal.View); sslr.Effect.FxDepthMap.SetResource(_gDepthBuffer.View); sslr.Effect.FxLightMap.SetResource(light?.View); sslr.Effect.TechHabrahabrVersion.DrawAllPasses(DeviceContext, 6); if (temporary != null) { DeviceContext.OutputMerger.SetTargets(temporary.TargetView); DeviceContextHolder.GetHelper<BlurHelper>().BlurReflectionVertically(DeviceContextHolder, target.View, _gBufferMaps.View); DeviceContext.OutputMerger.SetTargets(target.TargetView); DeviceContextHolder.GetHelper<BlurHelper>().BlurReflectionHorizontally(DeviceContextHolder, temporary.View, _gBufferMaps.View); } if (limitedBy != null) { DeviceContext.OutputMerger.DepthStencilState = null; } }
private void DrawLights(TargetResourceTexture target, DepthStencilView limitedBy = null) { // set blending & prepare quad DeviceContext.OutputMerger.BlendState = DeviceContextHolder.AddBlendState; // proper render target if (limitedBy == null) { DeviceContext.OutputMerger.SetTargets(target.TargetView); DeviceContext.OutputMerger.DepthStencilState = null; } else { DeviceContext.OutputMerger.SetTargets(limitedBy, target.TargetView); DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.GreaterReadOnlyDepthState; } DeviceContext.ClearRenderTargetView(target.TargetView, ColorTransparent); // camera position & matrix _deferredLighting.FxWorldViewProjInv.SetMatrix(Camera.ViewProjInvert); _deferredLighting.FxEyePosW.Set(Camera.Position); _deferredLighting.FxScreenSize.Set(new Vector4(Width, Height, 1f / Width, 1f / Height)); // g-buffer _deferredLighting.FxBaseMap.SetResource(_gBufferBase.View); _deferredLighting.FxNormalMap.SetResource(_gBufferNormal.View); _deferredLighting.FxMapsMap.SetResource(_gBufferMaps.View); _deferredLighting.FxDepthMap.SetResource(_gDepthBuffer.View); // lights! if (UseShadows) { _deferredLighting.FxShadowMaps.SetResourceArray(_sunShadows.Splits.Take(EffectDeferredLight.NumSplits).Select(x => x.View).ToArray()); _deferredLighting.FxShadowViewProj.SetMatrixArray( _sunShadows.Splits.Take(EffectDeferredLight.NumSplits).Select(x => x.ShadowTransform).ToArray()); } else { _deferredLighting.FxShadowMaps.SetResource(null); } Sun?.Draw(DeviceContextHolder, Camera, UseDebugShadows ? SpecialLightMode.Debug : !UseShadows ? SpecialLightMode.Default : UseShadowsFilter ? SpecialLightMode.Shadows : SpecialLightMode.ShadowsWithoutFilter); if (!LimitLightsThroughGlass || limitedBy == null) { foreach (var light in Lights) { light.Draw(DeviceContextHolder, Camera, SpecialLightMode.Default); } } if (limitedBy != null) { DeviceContext.OutputMerger.DepthStencilState = null; } }
private void PrepareOutlineBuffer() { if (_outlineBuffer != null) return; _outlineBuffer = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm, SampleDescription); _outlineDepthBuffer = TargetResourceDepthTexture.Create(); if (!InitiallyResized) return; _outlineBuffer.Resize(DeviceContextHolder, Width, Height); _outlineDepthBuffer.Resize(DeviceContextHolder, Width, Height); }
public void Draw(DeviceContextHolder holder, ShaderResourceView view, TargetResourceTexture temporary) { // preparation holder.SaveRenderTargetAndViewport(); holder.QuadBuffers.Prepare(holder.DeviceContext, _effect.LayoutPT); // update those small texture UpdateNewAverateColor(holder, view); UpdateAdaptation(holder); holder.RestoreRenderTargetAndViewport(); holder.DeviceContext.OutputMerger.SetTargets(temporary.TargetView); holder.DeviceContext.ClearRenderTargetView(temporary.TargetView, BaseRenderer.ColorTransparent); _effect.FxInputMap.SetResource(view); _effect.FxBrightnessMap.SetResource(GetAdaptationTexture().View); _effect.TechTonemap.DrawAllPasses(holder.DeviceContext, 6); // update bloom texture (bright areas) UpdateBloom(holder, temporary.View); if (BloomDebug) { holder.RestoreRenderTargetAndViewport(); _effect.FxInputMap.SetResource(_bloomTexture.View); _effect.TechCopy.DrawAllPasses(holder.DeviceContext, 6); return; } // reset viewport holder.RestoreRenderTargetAndViewport(); _effect.FxInputMap.SetResource(temporary.View); _effect.FxBloomMap.SetResource(_bloomTexture.View); _effect.TechCombine.DrawAllPasses(holder.DeviceContext, 6); }