Exemplo n.º 1
0
        public void Process(DeviceContextHolder holder, ShaderResourceView depthView, ShaderResourceView normalsView, ICamera camera, float blurMultipler,
                            TargetResourceTexture blurTemporary, RenderTargetView target)
        {
            // Prepare SSLR and combine buffers
#if SSLR_PARAMETRIZED
            if (_sslrParamsChanged)
            {
                _sslrParamsChanged = false;
                var effect = DeviceContextHolder.GetEffect <EffectPpDarkSslr>();
                effect.FxStartFrom.Set(_sslrStartFrom);
                effect.FxFixMultiplier.Set(_sslrFixMultiplier);
                effect.FxOffset.Set(_sslrOffset);
                effect.FxGlowFix.Set(_sslrGrowFix);
                effect.FxDistanceThreshold.Set(_sslrDistanceThreshold);
            }
#endif

            Draw(holder, depthView, normalsView, camera);
            _blurHelper.BlurDarkSslr(holder, BufferResult, blurTemporary, 4f * blurMultipler);
            FinalStep(holder, BufferScene.View, BufferResult.View, BufferBaseReflection.View,
                      normalsView, camera, target);
        }
Exemplo n.º 2
0
        protected override void DrawSceneToBuffer()
        {
            if (!UseSslr && !UseAo)
            {
                base.DrawSceneToBuffer();
                return;
            }

            DrawPrepare();

            if (_sslrHelper == null)
            {
                _sslrHelper = DeviceContextHolder.GetHelper <DarkSslrHelper>();
            }

            if (_blurHelper == null)
            {
                _blurHelper = DeviceContextHolder.GetHelper <BlurHelper>();
            }

            // Draw scene to G-buffer to get normals, depth and base reflection
            DeviceContext.Rasterizer.SetViewports(Viewport);
            DeviceContext.OutputMerger.SetTargets(DepthStencilView, _sslrBufferBaseReflection?.TargetView, _gBufferNormals.TargetView, _gBufferDepth.TargetView);
            DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
            DeviceContext.ClearRenderTargetView(_gBufferNormals.TargetView, (Color4) new Vector4(0.5f));

            if (_sslrBufferBaseReflection != null)
            {
                DeviceContext.ClearRenderTargetView(_sslrBufferBaseReflection.TargetView, (Color4) new Vector4(0));
            }

            DeviceContext.ClearRenderTargetView(_gBufferDepth.TargetView, (Color4) new Vector4(1f));

            DeviceContext.OutputMerger.DepthStencilState = null;
            DeviceContext.OutputMerger.BlendState        = null;
            DeviceContext.Rasterizer.State = null;

            if (ShowroomNode != null)
            {
                ShowroomNode.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer);
            }
            else
            {
                if (_mirror != null)
                {
                    if (FlatMirror && !FlatMirrorBlurred)
                    {
                        _mirror.DrawReflection(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer);
                    }
                    else
                    {
                        _mirror.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer);
                    }
                }
            }

            CarNode?.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer);

            // AO?
            if (UseAo)
            {
                var aoHelper = _aoHelper;
                if (aoHelper == null)
                {
                    aoHelper = _aoHelper = GetAoHelper();
                }

                if (AoType == AoType.Hbao)
                {
                    UseSslr = true;
                    SetInnerBuffer(_sslrBufferScene);
                    DrawPreparedSceneToBuffer();
                    (aoHelper as HbaoHelper)?.Prepare(DeviceContextHolder, _sslrBufferScene.View);
                    SetInnerBuffer(null);
                }

                aoHelper.Draw(DeviceContextHolder,
                              _gBufferDepth.View,
                              _gBufferNormals.View,
                              ActualCamera, _aoBuffer.TargetView);
                aoHelper.Blur(DeviceContextHolder, _aoBuffer, InnerBuffer, Camera);

                var effect = Effect;
                effect.FxAoMap.SetResource(_aoBuffer.View);
                Effect.FxAoPower.Set(AoOpacity);
                effect.FxScreenSize.Set(new Vector4(Width, Height, 1f / Width, 1f / Height));

                if (AoDebug)
                {
                    DeviceContextHolder.GetHelper <CopyHelper>().Draw(DeviceContextHolder, _aoBuffer.View, InnerBuffer.TargetView);
                    return;
                }
            }

            if (UseSslr && _sslrBufferBaseReflection != null)
            {
                // Draw actual scene to _sslrBufferScene
                SetInnerBuffer(_sslrBufferScene);
                DrawPreparedSceneToBuffer();
                SetInnerBuffer(null);

                // Prepare SSLR and combine buffers
#if SSLR_PARAMETRIZED
                if (_sslrParamsChanged)
                {
                    _sslrParamsChanged = false;
                    var effect = DeviceContextHolder.GetEffect <EffectPpDarkSslr>();
                    effect.FxStartFrom.Set(_sslrStartFrom);
                    effect.FxFixMultiplier.Set(_sslrFixMultiplier);
                    effect.FxOffset.Set(_sslrOffset);
                    effect.FxGlowFix.Set(_sslrGrowFix);
                    effect.FxDistanceThreshold.Set(_sslrDistanceThreshold);
                }
#endif

                _sslrHelper.Draw(DeviceContextHolder,
                                 _gBufferDepth.View,
                                 _sslrBufferBaseReflection.View,
                                 _gBufferNormals.View,
                                 ActualCamera, _sslrBufferResult.TargetView);
                _blurHelper.BlurDarkSslr(DeviceContextHolder, _sslrBufferResult, InnerBuffer, (float)(2f * ResolutionMultiplier));
                _sslrHelper.FinalStep(DeviceContextHolder,
                                      _sslrBufferScene.View,
                                      _sslrBufferResult.View,
                                      _sslrBufferBaseReflection.View,
                                      _gBufferNormals.View,
                                      ActualCamera, InnerBuffer.TargetView);
            }
            else
            {
                DrawPreparedSceneToBuffer();
            }
        }