Esempio n. 1
0
        void InternalSetRtvs(DepthStencilView dsv, params IRtvBindable[] rtvs)
        {
            if (m_tmpRtvs == null)
            {
                m_tmpRtvs = new RenderTargetView[8];
            }

            // Init RenderTargetView-s
            MyRenderProxy.Assert(rtvs.Length <= m_tmpRtvs.Length);
            for (int i = 0; i < rtvs.Length; i++)
            {
                IRtvBindable rtvBindable = rtvs[i];

                RenderTargetView dxObject = null;
                if (rtvBindable != null)
                {
                    dxObject = rtvBindable.Rtv;
                }
                m_tmpRtvs[i] = dxObject;
            }
            for (int i = rtvs.Length; i < m_tmpRtvs.Length; i++)
            {
                m_tmpRtvs[i] = null;
            }

            m_state.SetTargets(dsv, m_tmpRtvs, rtvs.Length);
            CheckErrors();
        }
Esempio n. 2
0
        internal static void Run(IRtvBindable dst, MyGBuffer gbuffer, ISrvBindable resolvedDepth)
        {
            RC.ClearRtv(dst, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);

            mapping.WriteAndPosition(ref Params.Data);
            FillRandomVectors(mapping);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.BindRawCB_FrameConstants(RC);
            }
            RC.AllShaderStages.SetConstantBuffer(1, paramsCB);

            RC.PixelShader.Set(m_ps);
            RC.SetRtv(dst);

            RC.PixelShader.SetSrvs(0, gbuffer);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.SetSrv(5, resolvedDepth);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);

            DrawFullscreenQuad();
            RC.ResetTargets();
        }
        public static void Draw(IRtvBindable renderTarget)
        {
            ISrvBindable srvBind = null;
            if (m_selRtvTexture != null)
                srvBind = m_selRtvTexture;
            if (m_selUavTexture != null)
                srvBind = m_selUavTexture;
            if (m_selBorrowedRtvTexture != null)
                srvBind = m_selBorrowedRtvTexture;
            if (m_selBorrowedUavTexture != null)
                srvBind = m_selBorrowedUavTexture;

            if (srvBind == null) // no texture is selected
                return;

            if (m_ps == PixelShaderId.NULL)
                m_ps = MyShaders.CreatePs("Debug/DebugRt.hlsl");

            MyRenderContext RC = MyImmediateRC.RC;
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.SetRtv(renderTarget);
            RC.SetBlendState(null);
            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, srvBind);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            MyScreenPass.DrawFullscreenQuad();

            Deselect();
        }
        internal override void Cleanup()
        {
            base.Cleanup();

            Dsv = null;
            Rtv = null;
        }
Esempio n. 5
0
 private static void DebugDraw(ISrvBindable src, IRtvBindable dst, MyViewport viewport)
 {
     RC.PixelShader.Set(m_copyPS);
     RC.SetRtv(dst);
     RC.PixelShader.SetSrv(0, src);
     MyScreenPass.DrawFullscreenQuad(viewport);
 }
Esempio n. 6
0
        internal static void Run(IRtvBindable dst, MyGBuffer gbuffer)
        {
            RC.ClearRtv(dst, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);
            mapping.WriteAndPosition(ref Params.Data);
            FillRandomVectors(mapping);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
                RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            else
                MyStereoRender.BindRawCB_FrameConstants(RC);
            RC.AllShaderStages.SetConstantBuffer(1, paramsCB);

            RC.PixelShader.Set(m_ps);
            RC.SetRtv(dst);

            RC.PixelShader.SetSrvs(0, gbuffer);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.SetSrv(5, gbuffer.ResolvedDepthStencil.SrvDepth);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);

            DrawFullscreenQuad();
            RC.ResetTargets();
        }
 internal static void RunFullscreenSampleFreq(IRtvBindable RT)
 {
     Debug.Assert(MyRender11.MultisamplingEnabled);
     RC.SetDepthStencilState(MyDepthStencilStateManager.TestEdgeStencil, 0x80);
     RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, RT);
     DrawFullscreenQuad();
     RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
 }
Esempio n. 8
0
        static void DrawBlurYPS(IRtvBindable dst, MyViewport viewport)
        {
            RC.SetRtv(dst);
            RC.PixelShader.Set(m_blurYPS);
            RC.PixelShader.SetSrv(0, m_fullResAOZTexture);

            MyScreenPass.DrawFullscreenQuad(viewport);
        }
Esempio n. 9
0
 public static void DisplayHistogram(IRtvBindable output, ISrvBindable avgLumSrv, ISrvTexture histogram)
 {
     RC.PixelShader.SetSrvs(0, histogram, avgLumSrv);
     RC.PixelShader.Set(m_drawHistogram);
     RC.SetRtv(output);
     MyScreenPass.DrawFullscreenQuad(new MyViewport(64, 64, 512, 64));
     //m_histogram.Release();
     //m_histogram = null;
 }
Esempio n. 10
0
 static void DrawLinearDepthPS(ISrvBindable resolvedDepth, IRtvBindable rtv, MyViewport viewport)
 {
     RC.PixelShader.Set(m_linearizeDepthPS);
     //RC.SetRtv(m_fullResViewDepthTarget);
     RC.SetRtv(rtv);
     RC.PixelShader.SetSrv(0, resolvedDepth);
     MyScreenPass.DrawFullscreenQuad(viewport);
     RC.SetRtv(null);
 }
Esempio n. 11
0
 public static void DisplayHistogram(IRtvBindable output, ISrvBindable avgLumSrv, ISrvTexture histogram)
 {
     RC.PixelShader.SetSrvs(0, histogram, avgLumSrv);
     RC.PixelShader.Set(m_drawHistogram);
     RC.SetRtv(output);
     MyScreenPass.DrawFullscreenQuad(new MyViewport(64, 64, 512, 64));
     //m_histogram.Release();
     //m_histogram = null;
 }
Esempio n. 12
0
 private static void DrawSprites(IRtvBindable texture)
 {
     GetRenderProfiler().StartProfilingBlock("MySpritesRenderer.Draw");
     MyStatsUpdater.Timestamps.Update(ref MyStatsUpdater.Timestamps.PreDrawSprites_Draw);
     MyGpuProfiler.IC_BeginBlock("SpriteRenderer");
     MySpritesRenderer.Draw(texture, new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y));
     MyGpuProfiler.IC_EndBlock();
     MyStatsUpdater.Timestamps.Update(ref MyStatsUpdater.Timestamps.PostDrawSprites_Draw);
     GetRenderProfiler().EndProfilingBlock();
 }
Esempio n. 13
0
        internal static void Run(IRtvBindable dst, ISrvBindable src, IBlendState bs = null)
        {
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Esempio n. 14
0
        internal void SetRtv(IDsvBindable dsvBind, IRtvBindable rtv)
        {
            DepthStencilView dsv = null;

            if (dsvBind != null)
            {
                dsv = dsvBind.Dsv;
            }
            InternalSetRtvs(dsv, rtv);
            CheckErrors();
        }
Esempio n. 15
0
        /// <summary>Render depth and normals of windows to the specified target</summary>
        /// <returns>True if windows to be rendered found</returns>
        /// <param name="squaredDistanceMin">Squared distance internal minor</param>
        internal static bool RenderWindowsDepthOnly(IDepthStencil depthStencil, IRtvBindable gbuffer1,
                                                    float squaredDistanceMin, float squaredDistanceMax)
        {
            int offset          = 0;
            int windowsCount    = 0;
            int windowsCountMax = WindowCountSafe;

            for (int it = 0; it < windowsCountMax; it++)
            {
                // Interval is [min, max)
                MyBillboard billboard = m_sortedBuffer[m_sorteWindowIndices[it]];
                if (billboard.DistanceSquared >= squaredDistanceMax)
                {
                    break;
                }

                if (billboard.DistanceSquared < squaredDistanceMin)
                {
                    offset++;
                }
                else
                {
                    windowsCount++;
                }
            }

            if (windowsCount == 0)
            {
                return(false);
            }

            TransferDataBillboards(offset, windowsCount, ref m_arrayDataWindows);

            RC.SetRtv(depthStencil, MyDepthStencilAccess.ReadWrite, gbuffer1);
            BindResourcesCommon();

            RC.SetBlendState(null);
            RC.VertexShader.Set(m_vsDepthOnly);
            RC.PixelShader.Set(m_psDepthOnly);


            if (!MyStereoRender.Enable)
            {
                RC.DrawIndexed(m_windowCount * 6, 0, 0);
            }
            else
            {
                MyStereoRender.DrawIndexedBillboards(RC, m_windowCount * 6, 0, 0);
            }
            MyStatsUpdater.Passes.DrawBillboards++;

            RC.SetRasterizerState(null);
            return(true);
        }
Esempio n. 16
0
        internal static void Run(IRtvBindable dst, ISrvBindable src, IBlendState bs = null)
        {
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Esempio n. 17
0
        internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState, IDepthStencilState depthStencilState, int stencilMask)
        {
            RC.SetDepthStencilState(depthStencilState, stencilMask);
            RC.SetBlendState(blendState);
            RC.SetRasterizerState(null);
            RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource);
            RC.PixelShader.SetSrv(0, sourceResource);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Esempio n. 18
0
        internal static void Run(IRtvBindable destination, ISrvBindable source)
        {
            RC.SetBlendState(null);

            RC.SetInputLayout(null);
            RC.PixelShader.Set(m_ps);

            RC.SetRtv(destination);
            RC.PixelShader.SetSrv(0, source);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.Size.X, destination.Size.Y));
        }
        public void CopyRedToAll(IRtvBindable output, ISrvTexture source)
        {
            MyRenderContext RC = MyRender11.RC;
            RC.SetBlendState(null);
            RC.SetRtv(output);

            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, source);
            MyScreenPass.DrawFullscreenQuad();

            RC.ResetTargets();
        }
Esempio n. 20
0
 internal static void RunFullscreenPixelFreq(IRtvBindable RT)
 {
     if (MyRender11.MultisamplingEnabled)
     {
         RC.SetDepthStencilState(MyDepthStencilStateManager.TestEdgeStencil, 0);
     }
     RC.SetRtvs(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, RT);
     DrawFullscreenQuad();
     if (MyRender11.MultisamplingEnabled)
     {
         RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
     }
 }
Esempio n. 21
0
        public void CopyRedToAll(IRtvBindable output, ISrvTexture source)
        {
            MyRenderContext RC = MyRender11.RC;

            RC.SetBlendState(null);
            RC.SetRtv(output);

            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, source);
            MyScreenPass.DrawFullscreenQuad();

            RC.ResetTargets();
        }
Esempio n. 22
0
        internal static void ClearAlpha(IRtvBindable destination)
        {
            RC.SetBlendState(MyBlendStateManager.BlendAdditive);

            RC.SetInputLayout(null);
            RC.PixelShader.Set(m_clearAlphaPs);

            RC.SetRtv(destination);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.Size.X, destination.Size.Y));

            RC.SetBlendState(null);
        }
Esempio n. 23
0
        internal static void ClearAlpha(IRtvBindable destination)
        {
            RC.SetBlendState(MyBlendStateManager.BlendAdditive);

            RC.SetInputLayout(null);
            RC.PixelShader.Set(m_clearAlphaPs);

            RC.SetRtv(destination);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.Size.X, destination.Size.Y));

            RC.SetBlendState(null);
        }
Esempio n. 24
0
        /// <summary>Render depth and normals of windows to the specified target</summary>
        /// <returns>True if glass to be rendered found</returns>
        /// <param name="squaredDistanceMin">Squared distance internal minor</param>
        internal static bool RenderGlassDepthOnly(IDepthStencil depthStencil, IRtvBindable gbuffer1,
                                                  float squaredDistanceMin, float squaredDistanceMax)
        {
            int offset       = 0;
            int windowsCount = 0;

            for (int it = 0; it < m_squaredDistances.Count; it++)
            {
                // Interval is [min, max)
                double squaredDistance = m_squaredDistances[it].Item2;
                if (squaredDistance >= squaredDistanceMax)
                {
                    break;
                }

                if (squaredDistance < squaredDistanceMin)
                {
                    offset++;
                }
                else
                {
                    windowsCount++;
                }
            }

            if (windowsCount == 0)
            {
                return(false);
            }

            var pass = MyStaticGlassPass.Instance;

            pass.ViewProjection = MyRender11.Environment.Matrices.ViewProjectionAt0;
            pass.Viewport       = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            pass.BeginDepthOnly();

            RC.SetRtv(depthStencil, MyDepthStencilAccess.ReadWrite, gbuffer1);

            for (int it = offset; it < windowsCount; it++)
            {
                var renderable = m_squaredDistances[it].Item1;
                pass.RecordCommandsDepthOnly(renderable.RenderProxy);
            }

            pass.End();

            return(true);
        }
Esempio n. 25
0
 static void Resolve(bool blur, IRtvBindable dst, MyViewport viewport)
 {
     RC.SetRtv(dst);
     RC.PixelShader.SetSrv(0, m_quarterResAOTextureArray);
     if (blur)
     {
         RC.PixelShader.Set(m_reinterleaveAOPS_PreBlur);
         RC.PixelShader.SetSrv(1, m_fullResViewDepthTarget);
     }
     else
     {
         RC.PixelShader.Set(m_reinterleaveAOPS);
     }
     RC.PixelShader.SetSamplers(0, MySamplerStateManager.PointHBAOClamp);
     MyScreenPass.DrawFullscreenQuad(viewport);
 }
Esempio n. 26
0
        internal static void RunWithPixelStencilTest(IRtvBindable dst, ISrvBindable src, IBlendState bs = null,
            bool inverseTest = false, IDepthStencil depthStencil = null)
        {
            RC.SetDepthStencilState(null);
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.SetSrv(1, depthStencil == null ? MyGBuffer.Main.DepthStencil.SrvStencil : depthStencil.SrvStencil);
            if (!inverseTest)
                RC.PixelShader.Set(m_stencilTestPixelShader);
            else
                RC.PixelShader.Set(m_stencilInverseTestPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Esempio n. 27
0
        public static void Draw(IRtvBindable renderTarget)
        {
            ISrvBindable srvBind = null;

            if (m_selRtvTexture != null)
            {
                srvBind = m_selRtvTexture;
            }
            if (m_selUavTexture != null)
            {
                srvBind = m_selUavTexture;
            }
            if (m_selBorrowedRtvTexture != null)
            {
                srvBind = m_selBorrowedRtvTexture;
            }
            if (m_selBorrowedUavTexture != null)
            {
                srvBind = m_selBorrowedUavTexture;
            }

            if (srvBind == null) // no texture is selected
            {
                return;
            }

            if (m_ps == PixelShaderId.NULL)
            {
                m_ps = MyShaders.CreatePs("Debug/DebugRt.hlsl");
            }

            MyRenderContext RC = MyImmediateRC.RC;

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.SetRtv(renderTarget);
            RC.SetBlendState(null);
            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSrv(0, srvBind);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            MyScreenPass.DrawFullscreenQuad();

            Deselect();
        }
Esempio n. 28
0
        internal static void Run(IRtvBindable destination, ISrvBindable source, bool alphaBlended = false, MyViewport? customViewport = null)
        {
            if (alphaBlended)
                RC.SetBlendState(MyBlendStateManager.BlendAlphaPremult);
            else
                RC.SetBlendState(null);
            //context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            RC.SetInputLayout(null);
            RC.PixelShader.Set(m_copyPs);
        
            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResource(0, resource);
        
            RC.SetRtv(destination);
            RC.PixelShader.SetSrv(0, source);

            MyScreenPass.DrawFullscreenQuad(customViewport ?? new MyViewport(destination.Size.X, destination.Size.Y));
        }
Esempio n. 29
0
        internal static unsafe void RunForwardPostprocess(IRtvBindable rt, IDsvBindable depthDsv, ISrvBindable depthSrv,
                                                          ref Matrix viewMatrix, ref Matrix projMatrix)
        {
            MyGpuProfiler.IC_BeginBlock("Postprocess");
            var viewMatrixT = Matrix.Transpose(viewMatrix);
            var projMatrixT = Matrix.Transpose(projMatrix);
            var mapping     = MyMapping.MapDiscard(RC, TransformConstants);

            mapping.WriteAndPosition(ref viewMatrixT);
            mapping.WriteAndPosition(ref projMatrixT);
            mapping.WriteAndPosition(ref MyRender11.Environment.Data.EnvironmentLight.SunLightDirection);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, TransformConstants);

            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.SetRtv(rt);
            RC.PixelShader.SetSrv(0, depthSrv);
            MyFileTextureManager texManager = MyManagers.FileTextures;

            RC.PixelShader.SetSrv(MyCommon.SKYBOX_SLOT, texManager.GetTexture(MyRender11.Environment.Data.Skybox, MyFileTextureEnum.CUBEMAP, true));
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.Set(m_ps);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(m_viewportSize, m_viewportSize));
            MyGpuProfiler.IC_EndBlock();

            var nearestAtmosphereId = MyAtmosphereRenderer.GetNearestAtmosphereId();

            if (nearestAtmosphereId != null)
            {
                MyGpuProfiler.IC_BeginBlock("Atmosphere");
                RC.PixelShader.SetSrv(0, depthSrv);
                var viewProj = viewMatrix * projMatrix;
                MyAtmosphereRenderer.RenderEnvProbe(MyRender11.Environment.Matrices.CameraPosition, ref viewProj, nearestAtmosphereId.Value);

                MyGpuProfiler.IC_EndBlock();
            }

            RC.SetRtv(null);
        }
Esempio n. 30
0
        internal static void RunWithPixelStencilTest(IRtvBindable dst, ISrvBindable src, IBlendState bs = null, bool inverseTest = false)
        {
            RC.SetDepthStencilState(null);
            RC.SetBlendState(bs);
            RC.SetRasterizerState(null);
            RC.SetRtv(dst);
            RC.PixelShader.SetSrv(0, src);
            RC.PixelShader.SetSrv(1, MyGBuffer.Main.DepthStencil.SrvStencil);
            if (!inverseTest)
            {
                RC.PixelShader.Set(m_stencilTestPixelShader);
            }
            else
            {
                RC.PixelShader.Set(m_stencilInverseTestPixelShader);
            }

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
Esempio n. 31
0
 static void BlendHighlight(IRtvBindable target, ISrvBindable outlined, ICustomTexture fxaaTarget, IDepthStencil depthStencilCopy)
 {
     MyGpuProfiler.IC_BeginBlock("Highlight Blending");
     ProfilerShort.Begin("Highlight Blending");
     if (fxaaTarget != null)
     {
         MyBlendTargets.RunWithStencil(
             fxaaTarget.SRgb,
             outlined,
             MyBlendStateManager.BlendAdditive,
             MyDepthStencilStateManager.TestHighlightOuterStencil,
             HIGHLIGHT_STENCIL_MASK,
             depthStencilCopy);
         MyBlendTargets.RunWithStencil(
             fxaaTarget.SRgb,
             outlined,
             MyBlendStateManager.BlendTransparent,
             MyDepthStencilStateManager.TestHighlightInnerStencil,
             HIGHLIGHT_STENCIL_MASK,
             depthStencilCopy);
     }
     else
     {
         if (MyRender11.MultisamplingEnabled)
         {
             MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendAdditive, false, depthStencilCopy);
             MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendTransparent, true, depthStencilCopy);
         }
         else
         {
             MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendAdditive,
                                           MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK,
                                           depthStencilCopy);
             MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendTransparent,
                                           MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK,
                                           depthStencilCopy);
         }
     }
     ProfilerShort.End();
     MyGpuProfiler.IC_EndBlock();
 }
Esempio n. 32
0
        static void DrawDeinterleavedDepth(MyViewport viewport)
        {
            var qViewport = GetQuarterViewport(viewport);

            RC.PixelShader.Set(m_deinterleaveDepthPS);
            RC.PixelShader.SetSrv(0, m_fullResViewDepthTarget);

            var rtvs = new IRtvBindable[MAX_NUM_MRTS];

            for (int sliceIndex = 0; sliceIndex < NUM_SLICES; sliceIndex += MAX_NUM_MRTS)
            {
                for (int i = 0; i < MAX_NUM_MRTS; i++)
                {
                    rtvs[i] = m_quarterResViewDepthTextureArray.SubresourceRtv(sliceIndex + i);
                }
                RC.SetRtvs(rtvs);
                RC.PixelShader.SetConstantBuffer(1, m_perPassCBs[sliceIndex]);

                MyScreenPass.DrawFullscreenQuad(qViewport);
            }
        }
Esempio n. 33
0
        internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState,
            IDepthStencilState depthStencilState = null, int stencilMask = 0x0, IDepthStencil depthStencil = null)
        {
            RC.SetBlendState(blendState);
            RC.SetRasterizerState(null);
            if (depthStencilState == null)
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
                RC.SetRtv(null, MyDepthStencilAccess.ReadOnly, destinationResource);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilMask);
                RC.SetRtv(depthStencil ?? MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource);
            }

            RC.PixelShader.SetSrv(0, sourceResource);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
        /// <summary>Render depth and normals of windows to the specified target</summary>
        /// <returns>True if glass to be rendered found</returns>
        /// <param name="squaredDistanceMin">Squared distance internal minor</param>
        internal static bool RenderGlassDepthOnly(IDepthStencil depthStencil, IRtvBindable gbuffer1,
            float squaredDistanceMin, float squaredDistanceMax)
        {
            int offset = 0;
            int windowsCount = 0;
            for (int it = 0; it < m_squaredDistances.Count; it++)
            {
                // Interval is [min, max)
                double squaredDistance = m_squaredDistances[it].Item2;
                if (squaredDistance >= squaredDistanceMax)
                    break;

                if (squaredDistance < squaredDistanceMin)
                    offset++;
                else
                    windowsCount++;
            }

            if (windowsCount == 0)
                return false;

            var pass = MyStaticGlassPass.Instance;
            pass.ViewProjection = MyRender11.Environment.Matrices.ViewProjectionAt0;
            pass.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            pass.BeginDepthOnly();

            RC.SetRtv(depthStencil, MyDepthStencilAccess.ReadWrite, gbuffer1);

            for (int it = offset; it < windowsCount; it++)
            {
                var renderable = m_squaredDistances[it].Item1;
                pass.RecordCommandsDepthOnly(renderable.RenderProxy);
            }

            pass.End();

            return true;
        }
Esempio n. 35
0
        internal static void Run(IRtvBindable destination, ISrvBindable source, bool alphaBlended = false, MyViewport?customViewport = null)
        {
            if (alphaBlended)
            {
                RC.SetBlendState(MyBlendStateManager.BlendAlphaPremult);
            }
            else
            {
                RC.SetBlendState(null);
            }
            //context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            RC.SetInputLayout(null);
            RC.PixelShader.Set(m_copyPs);

            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResource(0, resource);

            RC.SetRtv(destination);
            RC.PixelShader.SetSrv(0, source);

            MyScreenPass.DrawFullscreenQuad(customViewport ?? new MyViewport(destination.Size.X, destination.Size.Y));
        }
Esempio n. 36
0
        internal unsafe static void RunForwardPostprocess(IRtvBindable rt, ISrvBindable depth, ref Matrix viewMatrix, uint? atmosphereId)
        {
            MyGpuProfiler.IC_BeginBlock("Postprocess");
            var transpose = Matrix.Transpose(viewMatrix);
            var mapping = MyMapping.MapDiscard(RC, MyCommon.ProjectionConstants);
            mapping.WriteAndPosition(ref transpose);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);

            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.SetRtv(rt);
            RC.PixelShader.SetSrv(0, depth);
            MyFileTextureManager texManager = MyManagers.FileTextures;
            RC.PixelShader.SetSrv(MyCommon.SKYBOX_SLOT, texManager.GetTexture(MyRender11.Environment.Data.Skybox, MyFileTextureEnum.CUBEMAP, true));
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.Set(m_ps);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(m_viewportSize, m_viewportSize));
            MyGpuProfiler.IC_EndBlock();

            MyGpuProfiler.IC_BeginBlock("Atmosphere");
            if (atmosphereId != null)
            {
                var atmosphere = MyAtmosphereRenderer.GetAtmosphere(atmosphereId.Value);
                var constants = new AtmosphereConstants();
                //TODO(AF) These values are computed in MyAtmosphere as well. Find a way to remove the duplication
                var worldMatrix = atmosphere.WorldMatrix;
                worldMatrix.Translation -= MyRender11.Environment.Matrices.CameraPosition;

                double distance = worldMatrix.Translation.Length();
                double atmosphereTop = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier * atmosphere.PlanetScaleFactor * atmosphere.Settings.RayleighTransitionModifier;
                float rayleighHeight = atmosphere.Settings.RayleighHeight;
                float t = 0.0f;
                if (distance > atmosphereTop)
                {
                    if (distance > atmosphereTop * 2.0f)
                    {
                        t = 1.0f;
                    }
                    else
                    {
                        t = (float)((distance - atmosphereTop) / atmosphereTop);
                    }
                }
                rayleighHeight = MathHelper.Lerp(atmosphere.Settings.RayleighHeight, atmosphere.Settings.RayleighHeightSpace, t);


                constants.PlanetCentre = (Vector3)worldMatrix.Translation;
                constants.AtmosphereRadius = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier;
                constants.GroundRadius = atmosphere.PlanetRadius * 1.01f * atmosphere.Settings.SeaLevelModifier;
                constants.BetaRayleighScattering = atmosphere.BetaRayleighScattering / atmosphere.Settings.RayleighScattering;
                constants.BetaMieScattering = atmosphere.BetaMieScattering / atmosphere.Settings.MieColorScattering;
                constants.HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie * new Vector2(rayleighHeight, atmosphere.Settings.MieHeight);
                constants.MieG = atmosphere.Settings.MieG;
                constants.PlanetScaleFactor = atmosphere.PlanetScaleFactor;
                constants.AtmosphereScaleFactor = atmosphere.AtmosphereScaleFactor;
                constants.Intensity = atmosphere.Settings.Intensity;
                constants.FogIntensity = atmosphere.Settings.FogIntensity;
            
                var cb = MyCommon.GetObjectCB(sizeof(AtmosphereConstants));
            
                mapping = MyMapping.MapDiscard(RC, cb);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.SetBlendState(MyBlendStateManager.BlendAdditive);
                RC.PixelShader.SetConstantBuffer(2, cb);
                RC.PixelShader.SetSrv(2, MyAtmosphereRenderer.GetAtmosphereLuts(atmosphereId.Value).TransmittanceLut);
                RC.PixelShader.Set(m_atmosphere);

                MyScreenPass.DrawFullscreenQuad(new MyViewport(MyEnvironmentProbe.CubeMapResolution, MyEnvironmentProbe.CubeMapResolution));
            }
            MyGpuProfiler.IC_EndBlock();

            RC.SetRtv(null);

        }
Esempio n. 37
0
        internal static unsafe void Render(MyRenderContext RC, IDepthStencil ds, IRtvBindable rtv)
        {
            bool debugDraw = MyRender11.Settings.DrawOcclusionQueriesDebug;

            if (m_vb == null || m_tempBuffer2.Length < m_queries.Count)
            {
                int allocCount = System.Math.Max(m_queries.Count * 3 / 2, 32);
                System.Diagnostics.Debug.Assert(allocCount < 256);

                if (m_vb == null)
                {
                    m_vb = VRage.Render11.Common.MyManagers.Buffers.CreateVertexBuffer("MyOcclusionQueryRenderer.VB", allocCount,
                                                                                       sizeof(MyVbConstantElement), usage: SharpDX.Direct3D11.ResourceUsage.Dynamic);
                }
                else
                {
                    VRage.Render11.Common.MyManagers.Buffers.Resize(m_vb, allocCount);
                }
                m_tempBuffer  = new MyVbConstantElement[allocCount];
                m_tempBuffer2 = new MyOcclusionQuery[allocCount];
            }

            VRage.Profiler.ProfilerShort.Begin("Gather");
            int   ctr         = 0;
            float currentTime = MyCommon.TimerMs;

            foreach (var item in m_queries)
            {
                Vector3 cameraPos = item.Position - MyRender11.Environment.Matrices.CameraPosition;
                if (debugDraw)
                {
                    item.LastResult = 0;
                }
                else
                {
                    if (item.Running)
                    {
                        var result = item.Query.GetResult(false);
                        if (result != -1)
                        {
                            var dist    = cameraPos.Length();
                            var viewPos = new Vector3(item.Size, item.Size, dist);
                            var projPos = Vector3.Transform(viewPos, MyRender11.Environment.Matrices.Projection);
                            var pixels  = new Vector2(projPos.X, projPos.Y) * MyRender11.ResolutionF / 2;
                            var squared = System.Math.Abs(pixels.X * pixels.Y);
                            item.LastResult    = System.Math.Min(result / squared, 1.0f);
                            item.NextQueryTime = currentTime + item.FreqMinMs + m_random.NextFloat() * item.FreqRndMs;
                            item.Running       = false;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                if (!item.Visible || currentTime < item.NextQueryTime)
                {
                    continue;
                }

                item.Running = true;

                var data = new MyVbConstantElement
                {
                    Position = cameraPos,
                    Size     = item.Size
                };
                m_tempBuffer2[ctr] = item.Query;
                m_tempBuffer[ctr]  = data;
                ctr++;

                item.Visible = false;
            }

            if (ctr > 0)
            {
                VRage.Profiler.ProfilerShort.BeginNextBlock("Setup");
                RC.SetInputLayout(m_inputLayout);
                RC.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);

                RC.VertexShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

                RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
                RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);

                RC.VertexShader.Set(m_vs);
                if (debugDraw)
                {
                    RC.PixelShader.Set(m_ps);
                    RC.SetRtv(ds, MyDepthStencilAccess.ReadOnly, rtv);
                }
                else
                {
                    RC.SetRtv(ds, MyDepthStencilAccess.ReadOnly, null);
                    RC.PixelShader.Set(null);
                }

                VRage.Profiler.ProfilerShort.BeginNextBlock("Map");
                MyMapping mappingVb = MyMapping.MapDiscard(RC, m_vb);
                mappingVb.WriteAndPosition(m_tempBuffer, ctr);
                mappingVb.Unmap();

                RC.SetVertexBuffer(0, m_vb);

                VRage.Profiler.ProfilerShort.BeginNextBlock("Render");
                if (debugDraw)
                {
                    for (int i = 0; i < ctr; i++)
                    {
                        RC.DrawInstanced(4, 1, 0, i);
                    }
                }
                else
                {
                    for (int i = 0; i < ctr; i++)
                    {
                        m_tempBuffer2[i].Begin();
                        RC.DrawInstanced(4, 1, 0, i);

                        m_tempBuffer2[i].End();
                    }
                }
            }
            VRage.Profiler.ProfilerShort.End();

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
        }
        internal static void Draw(IRtvBindable renderTarget)
        {
            RC.SetScreenViewport();
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetInputLayout(m_inputLayout);

            RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
            RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);

            RC.VertexShader.Set(m_vs);
            RC.PixelShader.Set(m_ps);

            RC.SetRtv(MyGBuffer.Main.ResolvedDepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget);

            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);

            RC.SetBlendState(MyBlendStateManager.BlendTransparent);

            SortTransparent();
            var transpose = Matrix.Transpose(MyRender11.Environment.Matrices.ViewProjectionAt0);
            var mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants);
            mapping.WriteAndPosition(ref transpose);
            mapping.Unmap();

            CheckBufferSize(m_vertexList.Count);

            RC.SetVertexBuffer(0, m_VB);

            if (m_vertexList.Count > 0)
            {
                mapping = MyMapping.MapDiscard(m_VB);
                mapping.WriteAndPosition(m_vertexList.GetInternalArray(), m_vertexList.Count);
                mapping.Unmap();
            }

            RC.Draw(m_vertexList.Count, 0);

            if (m_debugMeshes.Count > 0)
            {
                var transposeViewProj = Matrix.Transpose(MyRender11.Environment.Matrices.ViewProjection);
                mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants);
                mapping.WriteAndPosition(ref transposeViewProj);
                mapping.Unmap();
            }

            foreach (var mesh in m_debugMeshes.Values)
            {
                if (mesh.depth)
                    RC.SetRtv(MyGBuffer.Main.ResolvedDepthStencil, MyDepthStencilAccess.ReadWrite, renderTarget);
                else
                    RC.SetRtv(renderTarget);

                if (mesh.edges)
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.NocullWireframeRasterizerState);
                }
                else
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
                }

                RC.SetVertexBuffer(0, mesh.vbuffer);
                RC.Draw(mesh.vbuffer.ElementCount, 0);
            }

            RC.SetBlendState(null);

            m_vertexList.Clear();
            m_postSortVertexList.Clear();
            m_triangleSortDistance.Clear();
            m_sortedIndices.Clear();
        }
Esempio n. 39
0
        internal override void Cleanup()
        {
            base.Cleanup();

            Dsv = null;
            Rtv = null;
        }
Esempio n. 40
0
 public void CopyRedToAll(IRtvBindable output, ISrvTexture source)
 {
     m_postprocessRedToAll.CopyRedToAll(output, source);
 }
Esempio n. 41
0
        static void DrawBlurYPS(IRtvBindable dst, MyViewport viewport)
        {
            RC.SetRtv(dst);
            RC.PixelShader.Set(m_blurYPS);
            RC.PixelShader.SetSrv(0, m_fullResAOZTexture);

            MyScreenPass.DrawFullscreenQuad(viewport);
        }
Esempio n. 42
0
 private static void DebugDraw(ISrvBindable src, IRtvBindable dst, MyViewport viewport)
 {
     RC.PixelShader.Set(m_copyPS);
     RC.SetRtv(dst);
     RC.PixelShader.SetSrv(0, src);
     MyScreenPass.DrawFullscreenQuad(viewport);
 }
Esempio n. 43
0
        internal void AddForwardPass(int index, ref Matrix offsetedViewProjection, ref MatrixD viewProjection, MyViewport viewport, IDsvBindable dsv, IRtvBindable rtv)
        {
            int frustumMask = AddFrustum(ref viewProjection);

            MyForwardPass pass = MyObjectPoolManager.Allocate<MyForwardPass>();
            pass.DebugName = "EnvironmentProbe";
            pass.ProcessingMask = frustumMask;
            pass.ViewProjection = offsetedViewProjection;
            pass.Viewport = viewport;
            pass.FrustumIndex = index;
            pass.Dsv = dsv;
            pass.Rtv = rtv;

            pass.PerFrame();

            RenderingPasses[Size - 1] = pass;
        }
Esempio n. 44
0
        internal static unsafe void Draw(IRtvBindable renderTarget, IDepthStencil depth)
        {
            RC.SetScreenViewport();
            RC.SetPrimitiveTopology(PrimitiveTopology.LineList);
            RC.SetInputLayout(m_inputLayout);

            RC.SetRasterizerState(MyRasterizerStateManager.LinesRasterizerState);

            RC.VertexShader.Set(m_vs);
            RC.PixelShader.Set(m_ps);
            RC.SetBlendState(MyBlendStateManager.BlendAlphaPremult);

            RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);

            CheckBufferSize(m_vertices.Count);
            RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride);

            RC.SetRtv(depth, MyDepthStencilAccess.ReadOnly, renderTarget);
            
            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);

            if(m_batches.Count > 0)
            {
                var mapping = MyMapping.MapDiscard(m_VB.Buffer);
                mapping.WriteAndPosition(m_vertices.GetInternalArray(), 0, m_vertices.Count);
                mapping.Unmap();

                Matrix prevMatrix = Matrix.Zero;
                foreach (var batch in m_batches)
                {
                    Matrix matrix;
                    if (batch.CustomViewProjection.HasValue)
                    {
                        matrix = batch.CustomViewProjection.Value;
                    }
                    else
                    {
                        matrix = MyRender11.Environment.Matrices.ViewProjectionAt0;
                    }

                    if (prevMatrix != matrix)
                    {
                        prevMatrix = matrix;
                        var transpose = Matrix.Transpose(matrix);

                        mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants);
                        mapping.WriteAndPosition(ref transpose);
                        mapping.Unmap();
                    }

                    if(batch.IgnoreDepth)
                    {
                        RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);   
                    }
                    else
                    {
                        RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
                    }

                    RC.Draw(batch.VertexCount, batch.StartVertex);
                }
            }

            RC.SetDepthStencilState(null);
            RC.SetRasterizerState(null);

            m_vertices.Clear();

            foreach(var batch in m_batches)
            {
                m_batchesPool.Deallocate(batch);
            }
            m_batches.Clear();
        }
Esempio n. 45
0
        internal static void Run(IRtvBindable target, ICustomTexture fxaaTarget, IDepthStencil depthStencilCopy)
        {
            if (!HasHighlights)
                return;

            ProfilerShort.Begin("MyHighlight.Run");
            MyGpuProfiler.IC_BeginBlock("MyHighlight.Run");
            // set resolved depth/ stencil
            // render all with proper depth-stencil state
            // blur
            // blend to main target testing with stencil again

            MyHighlightPass.Instance.ViewProjection = MyRender11.Environment.Matrices.ViewProjectionAt0;
            MyHighlightPass.Instance.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);

            MyHighlightPass.Instance.PerFrame();
            MyHighlightPass.Instance.Begin();

            RC.VertexShader.SetSrvs(0, null, null, null, null, null, null);
            RC.GeometryShader.SetSrvs(0, null, null, null, null, null, null);
            RC.PixelShader.SetSrvs(0, null, null, null, null, null, null);
            RC.ComputeShader.SetSrvs(0, null, null, null, null, null, null);

            int samples = MyRender11.RenderSettings.AntialiasingMode.SamplesCount();
            IBorrowedRtvTexture rgba8_1 = MyManagers.RwTexturesPool.BorrowRtv("MyHighlight.Rgba8_1", Format.R8G8B8A8_UNorm_SRgb, samples);
            RC.ClearRtv(rgba8_1, new SharpDX.Color4(0, 0, 0, 0));
            RC.SetRtv(depthStencilCopy, MyDepthStencilAccess.DepthReadOnly, rgba8_1);

            float maxThickness = 0f;

            foreach (var pair in m_highlights)
            {
                MyActor actor = MyIDTracker<MyActor>.FindByID(pair.Key);
                MyRenderableComponent renderableComponent;
                if (actor == null || (renderableComponent = actor.GetRenderable()) == null)
                {
                    // If an actor has been removed without removing outlines, just remove the outlines too
                    m_keysToRemove.Add(pair.Key);
                    continue;
                }

                var renderLod = renderableComponent.Lods[renderableComponent.CurrentLod];
                var model = renderableComponent.GetModel();

                LodMeshId currentModelId;
                if (!MyMeshes.TryGetLodMesh(model, renderableComponent.CurrentLod, out currentModelId))
                {
                    Debug.Fail("Mesh for outlining not found!");
                    continue;
                }

                foreach (MyHighlightDesc descriptor in pair.Value)
                {

                    if (!renderableComponent.IsRenderedStandAlone)
                    {
                        MyGroupLeafComponent leafComponent = actor.GetGroupLeaf();
                        MyGroupRootComponent groupComponent = leafComponent.RootGroup;
                        if (groupComponent != null)
                            RecordMeshPartCommands(model, actor, groupComponent, groupComponent.m_proxy, descriptor, ref maxThickness);

                        continue;

                    }

                    if (descriptor.SectionIndex == -1)
                    {
                        RecordMeshPartCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref maxThickness);
                    }
                    else
                    {
                        RecordMeshSectionCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref maxThickness);
                    }
                }
            }

            MyHighlightPass.Instance.End();
            RC.SetBlendState(null);

            foreach (var outlineKey in m_keysToRemove)
                m_highlights.Remove(outlineKey);

            m_keysToRemove.SetSize(0);

            ISrvBindable initialSourceView = rgba8_1;
            IRtvBindable renderTargetview = rgba8_1;

            if (maxThickness > 0)
            {
                IBorrowedRtvTexture rgba8_2 = MyManagers.RwTexturesPool.BorrowRtv("MyHighlight.Rgba8_2", Format.R8G8B8A8_UNorm_SRgb);
                MyBlur.Run(renderTargetview, rgba8_2, initialSourceView,
                    (int)Math.Round(maxThickness), MyBlur.MyBlurDensityFunctionType.Exponential, 0.25f,
                    MyDepthStencilStateManager.IgnoreDepthStencil);
                rgba8_2.Release();
            }

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();

            BlendHighlight(target, rgba8_1, fxaaTarget, depthStencilCopy);
        }
Esempio n. 46
0
        // Returns the final image and copies it to renderTarget if non-null
        private static IRtvTexture DrawGameScene(IRtvBindable renderTarget)
        {
            MyGpuProfiler.IC_BeginBlock("Clear & Geometry Render");
                       
            PrepareGameScene();


            // todo: shouldn't be necessary
            if (true)
            {
                ProfilerShort.Begin("Clear");
                MyRender11.RC.ClearState();
                ProfilerShort.End();
            }

            if (MyStereoRender.Enable && MyStereoRender.EnableUsingStencilMask)
            {
                ProfilerShort.Begin("MyStereoStencilMask.Draw");
                MyGpuProfiler.IC_BeginBlock("MyStereoStencilMask.Draw");
                MyStereoStencilMask.Draw();
                MyGpuProfiler.IC_EndBlock();
                ProfilerShort.End();
            }

            MyGpuProfiler.IC_BeginBlock("MyGeometryRenderer.Render"); 
            Debug.Assert(m_commandLists.Count == 0, "Not all command lists executed last frame!");
            ProfilerShort.Begin("DynamicGeometryRenderer");
            DynamicGeometryRenderer.Render(m_commandLists, true);
            ProfilerShort.End();    // End function block
            if (MyScene.SeparateGeometry)
            {
                ProfilerShort.Begin("StaticGeometryRenderer");
                StaticGeometryRenderer.Render(m_commandLists, false);
                ProfilerShort.End();    // End function block
            }

            SendGlobalOutputMessages();
            ExecuteCommandLists(m_commandLists);
            MyGpuProfiler.IC_EndBlock();

#if !UNSHARPER_TMP
            MyManagers.EnvironmentProbe.FinalizeEnvProbes();
#endif

            // cleanup context atfer deferred lists
            if (true)
            {
                ProfilerShort.Begin("Clear3");
                MyRender11.RC.ClearState();
                ProfilerShort.End();
            }
            
            MyGpuProfiler.IC_EndBlock();

            ProfilerShort.Begin("Render decals - Opaque");
            MyGpuProfiler.IC_BeginBlock("Render decals - Opaque");
            MyImmediateRC.RC.CopyResource(MyGBuffer.Main.GBuffer1.Resource, MyGlobalResources.Gbuffer1Copy.Resource); // copy gbuffer1
            MyScreenDecals.Draw(false);
            MyGpuProfiler.IC_EndBlock();

            ProfilerShort.BeginNextBlock("Render foliage");
            MyGpuProfiler.IC_BeginBlock("Render foliage");
            m_foliageRenderer.Render();
            MyGpuProfiler.IC_EndBlock();

            MyGpuProfiler.IC_BeginBlock("GBuffer Resolve");
            ProfilerShort.BeginNextBlock("MySceneMaterials.MoveToGPU");
            MySceneMaterials.MoveToGPU();

            MyRender11.RC.ResetTargets();

            int nPasses = MyStereoRender.Enable ? 2 : 1;
            for (int i = 0; i < nPasses; i++)
            {
                if (MyStereoRender.Enable)
                    MyStereoRender.RenderRegion = i == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT;

                if (MultisamplingEnabled)
                {
                    MyRender11.RC.ClearDsv(MyScreenDependants.m_resolvedDepth, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0);
                    MyGpuProfiler.IC_BeginBlock("MarkAAEdges");
                    MyAAEdgeMarking.Run();
                    MyGpuProfiler.IC_EndBlock();
                    MyDepthResolve.Run(MyScreenDependants.m_resolvedDepth, MyGBuffer.Main.DepthStencil);
                }

                ProfilerShort.BeginNextBlock("Shadows");
                MyGpuProfiler.IC_BeginBlock("Shadows");
                IBorrowedUavTexture postProcessedShadows;
                if (MyScene.SeparateGeometry)
                {
                    MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades);
                    postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray);
                    //MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray,
                    //    DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades);
                    //postProcessedShadows =
                    //    DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray);
                }
                else
                {
                    postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(DynamicShadows.ShadowCascades.CascadeShadowmapArray);
                    //postProcessedShadows = MyManagers.Shadow.Evaluate();
                }
                MyGpuProfiler.IC_EndBlock();

                if (MySSAO.Params.Enabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO)
                {
                    ProfilerShort.BeginNextBlock("SSAO");
                    MyGpuProfiler.IC_BeginBlock("SSAO");
                    MySSAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);

                    if (MySSAO.Params.UseBlur)
                        MyBlur.Run(MyScreenDependants.m_ambientOcclusion, MyScreenDependants.m_ambientOcclusionHelper, MyScreenDependants.m_ambientOcclusion, clearColor : Color4.White);
                    MyGpuProfiler.IC_EndBlock();
                }
                else if (MyHBAO.Params.Enabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO)
                {
                    ProfilerShort.BeginNextBlock("HBAO");
                    MyGpuProfiler.IC_BeginBlock("HBAO");
                    MyHBAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, 
                        MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);
                    MyGpuProfiler.IC_EndBlock();
                }
                else
                {
                    MyRender11.RC.ClearRtv(MyScreenDependants.m_ambientOcclusion, Color4.White);
                }

                ProfilerShort.BeginNextBlock("Lights");
                MyGpuProfiler.IC_BeginBlock("Lights");
                if (m_debugOverrides.Lighting)
                    MyLightRendering.Render(postProcessedShadows);
                MyGpuProfiler.IC_EndBlock();
                postProcessedShadows.Release();

                if (MyRender11.DebugOverrides.Flares)
                    MyLightRendering.DrawFlares();
            }
            MyStereoRender.RenderRegion = MyStereoRegion.FULLSCREEN;
            MyGpuProfiler.IC_EndBlock();

            // Rendering for VR is solved inside of Transparent rendering
            ProfilerShort.BeginNextBlock("Transparent Pass");
            MyGpuProfiler.IC_BeginBlock("Transparent Pass");
            if (m_debugOverrides.Transparent)
                MyTransparentRendering.Render();
            MyGpuProfiler.IC_EndBlock();

            ProfilerShort.BeginNextBlock("PostProcess");
            MyGpuProfiler.IC_BeginBlock("PostProcess");
            MyGpuProfiler.IC_BeginBlock("Luminance reduction");
            IBorrowedUavTexture avgLum = null;

            if (MyRender11.Postprocess.EnableEyeAdaptation)
            {
                if (m_resetEyeAdaptation)
                {
                    MyLuminanceAverage.Reset();
                    m_resetEyeAdaptation = false;
                }

                avgLum = MyLuminanceAverage.Run(MyGBuffer.Main.LBuffer);
            }
            else
            {
                avgLum = MyLuminanceAverage.Skip();
            }

            MyGpuProfiler.IC_EndBlock();

            IBorrowedUavTexture histogram = null;
            if (MyRender11.Settings.DisplayHistogram)
                histogram = MyHdrDebugTools.CreateHistogram(MyGBuffer.Main.LBuffer, MyGBuffer.Main.SamplesCount);
            if (MyRender11.Settings.DisplayHdrIntensity)
            {
                MyHdrDebugTools.DisplayHdrIntensity(MyGBuffer.Main.LBuffer);
            }

            MyGpuProfiler.IC_BeginBlock("Bloom");
            IBorrowedUavTexture bloom;
            if (m_debugOverrides.Postprocessing && m_debugOverrides.Bloom)
            {
                bloom = MyBloom.Run(MyGBuffer.Main.LBuffer, MyGBuffer.Main.GBuffer2,
                    MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);
            }
            else
            {
                bloom = MyManagers.RwTexturesPool.BorrowUav("bloom_EightScreenUavHDR", MyRender11.ResolutionI.X / 8, MyRender11.ResolutionI.Y / 8, MyGBuffer.LBufferFormat);
                MyRender11.RC.ClearRtv(bloom, Color4.Black);
            }
            MyGpuProfiler.IC_EndBlock();

            
            MyGpuProfiler.IC_BeginBlock("Tone mapping");
            IBorrowedUavTexture tonemapped = MyToneMapping.Run(MyGBuffer.Main.LBuffer, avgLum, bloom, Postprocess.EnableTonemapping && m_debugOverrides.Postprocessing && m_debugOverrides.Tonemapping);
            bloom.Release();
            MyGpuProfiler.IC_EndBlock();

            IRtvTexture renderedImage;

            IBorrowedCustomTexture rgba8_0 = null;
            bool fxaa = MyRender11.FxaaEnabled; 
            if (fxaa)
            {
                rgba8_0 = MyManagers.RwTexturesPool.BorrowCustom("MyRender11.Rgb8_0");
                MyGpuProfiler.IC_BeginBlock("FXAA");
                MyFXAA.Run(rgba8_0.Linear, tonemapped);
                MyGpuProfiler.IC_EndBlock();

                renderedImage = rgba8_0.SRgb;
            }
            else
            {
                renderedImage = tonemapped;
            }
            ProfilerShort.Begin("Outline");
            if (MyOutline.AnyOutline())
            {
                IBorrowedRtvTexture outlined = MyOutline.Run();

                MyGpuProfiler.IC_BeginBlock("Outline Blending");
                ProfilerShort.Begin("Outline Blending");
                if (fxaa)
                {
                    MyBlendTargets.RunWithStencil(
                        rgba8_0.SRgb,
                        outlined,
                        MyBlendStateManager.BlendAdditive,
                        MyDepthStencilStateManager.TestOutlineMeshStencil,
                        0x40);
                    MyBlendTargets.RunWithStencil(
                        rgba8_0.SRgb,
                        outlined,
                        MyBlendStateManager.BlendTransparent,
                        MyDepthStencilStateManager.TestHighlightMeshStencil,
                        0x40);
                }
                else
                {
                    if (MyRender11.MultisamplingEnabled)
                    {
                        MyBlendTargets.RunWithPixelStencilTest(tonemapped, outlined, MyBlendStateManager.BlendAdditive);
                        MyBlendTargets.RunWithPixelStencilTest(tonemapped, outlined, MyBlendStateManager.BlendTransparent, true);
                    }
                    else
                    {
                        MyBlendTargets.RunWithStencil(tonemapped, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestOutlineMeshStencil, 0x40);
                        MyBlendTargets.RunWithStencil(tonemapped, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightMeshStencil, 0x40);
                    }
                }
                ProfilerShort.End();
                MyGpuProfiler.IC_EndBlock();

                outlined.Release();
            }
            ProfilerShort.End();

            if (renderTarget != null)
            {
                MyCopyToRT.Run(renderTarget, renderedImage);
            }

            if (MyRender11.Settings.DisplayHistogram)
            {
                if (renderTarget != null && avgLum != null)
                    MyHdrDebugTools.DisplayHistogram(renderTarget, avgLum, histogram);
            }
            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();

            if (rgba8_0 != null)
                rgba8_0.Release();
            if (histogram != null)
                histogram.Release();
            avgLum.Release();
            tonemapped.Release();

            // HOTFIX: MyDebugTextureDisplay uses borrowed textures. If we place MyDebugTextureDisplay to the different location, we will have problem with borrowed textures (comment by Michal)
            ProfilerShort.Begin("MyDebugTextureDisplay.Draw");
            MyGpuProfiler.IC_BeginBlock("MyDebugTextureDisplay.Draw");
            MyDebugTextureDisplay.Draw(MyRender11.Backbuffer);
            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();

            return renderedImage;
        }
        // Returns the final image and copies it to renderTarget if non-null
        private static IRtvTexture DrawGameScene(IRtvBindable renderTarget)
        {
            MyGpuProfiler.IC_BeginBlockAlways("ClearAndGeometryRender");

            PrepareGameScene();


            // todo: shouldn't be necessary
            if (true)
            {
                ProfilerShort.Begin("Clear");
                MyRender11.RC.ClearState();
                ProfilerShort.End();
            }

            if (MyStereoRender.Enable && MyStereoRender.EnableUsingStencilMask)
            {
                ProfilerShort.Begin("MyStereoStencilMask.Draw");
                MyGpuProfiler.IC_BeginBlock("MyStereoStencilMask.Draw");
                MyStereoStencilMask.Draw();
                MyGpuProfiler.IC_EndBlock();
                ProfilerShort.End();
            }

            MyGpuProfiler.IC_BeginBlock("MyGeometryRenderer.Render");
            Debug.Assert(m_commandLists.Count == 0, "Not all command lists executed last frame!");
            ProfilerShort.Begin("DynamicGeometryRenderer");
            DynamicGeometryRenderer.Render(m_commandLists, true);
            ProfilerShort.End();    // End function block
            if (MyScene.SeparateGeometry)
            {
                ProfilerShort.Begin("StaticGeometryRenderer");
                StaticGeometryRenderer.Render(m_commandLists, false);
                ProfilerShort.End();    // End function block
            }

            SendGlobalOutputMessages();
            ExecuteCommandLists(m_commandLists);
            MyGpuProfiler.IC_EndBlock();

#if !UNSHARPER_TMP
            MyManagers.EnvironmentProbe.FinalizeEnvProbes();
#endif

            // cleanup context atfer deferred lists
            if (true)
            {
                ProfilerShort.Begin("Clear3");
                MyRender11.RC.ClearState();
                ProfilerShort.End();
            }

            MyGpuProfiler.IC_EndBlockAlways();

            ProfilerShort.Begin("Render decals - Opaque");
            MyGpuProfiler.IC_BeginBlock("Render decals - Opaque");
            MyImmediateRC.RC.CopyResource(MyGBuffer.Main.GBuffer1.Resource, MyGlobalResources.Gbuffer1Copy.Resource); // copy gbuffer1
            MyScreenDecals.Draw(false);
            MyGpuProfiler.IC_EndBlock();

            ProfilerShort.BeginNextBlock("Render foliage");
            MyGpuProfiler.IC_BeginBlockAlways("RenderFoliage");
            m_foliageRenderer.Render();
            MyGpuProfiler.IC_EndBlockAlways();

            MyGpuProfiler.IC_BeginBlock("GBuffer Resolve");
            ProfilerShort.BeginNextBlock("MySceneMaterials.MoveToGPU");
            MySceneMaterials.MoveToGPU();

            MyRender11.RC.ResetTargets();

            int nPasses = MyStereoRender.Enable ? 2 : 1;
            for (int i = 0; i < nPasses; i++)
            {
                if (MyStereoRender.Enable)
                {
                    MyStereoRender.RenderRegion = i == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT;
                }

                if (MultisamplingEnabled)
                {
                    MyRender11.RC.ClearDsv(MyScreenDependants.m_resolvedDepth, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0);
                    MyGpuProfiler.IC_BeginBlock("MarkAAEdges");
                    MyAAEdgeMarking.Run();
                    MyGpuProfiler.IC_EndBlock();
                    MyDepthResolve.Run(MyScreenDependants.m_resolvedDepth, MyGBuffer.Main.DepthStencil);
                }

                ProfilerShort.BeginNextBlock("Shadows");
                MyGpuProfiler.IC_BeginBlockAlways("Shadows");
                IBorrowedUavTexture postProcessedShadows;
                if (MyScene.SeparateGeometry)
                {
                    MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades);
                    postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray);
                    //MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray,
                    //    DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades);
                    //postProcessedShadows =
                    //    DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray);
                }
                else
                {
                    postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(DynamicShadows.ShadowCascades.CascadeShadowmapArray);
                    //postProcessedShadows = MyManagers.Shadow.Evaluate();
                }
                MyGpuProfiler.IC_EndBlockAlways();

                if (MySSAO.Params.Enabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO)
                {
                    ProfilerShort.BeginNextBlock("SSAO");
                    MyGpuProfiler.IC_BeginBlockAlways("SSAO");
                    MySSAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);

                    if (MySSAO.Params.UseBlur)
                    {
                        MyBlur.Run(MyScreenDependants.m_ambientOcclusion, MyScreenDependants.m_ambientOcclusionHelper, MyScreenDependants.m_ambientOcclusion, clearColor: Color4.White);
                    }
                    MyGpuProfiler.IC_EndBlockAlways();
                }
                else if (MyHBAO.Params.Enabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO)
                {
                    ProfilerShort.BeginNextBlock("HBAO");
                    MyGpuProfiler.IC_BeginBlock("HBAO");
                    MyHBAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main,
                               MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);
                    MyGpuProfiler.IC_EndBlock();
                }
                else
                {
                    MyRender11.RC.ClearRtv(MyScreenDependants.m_ambientOcclusion, Color4.White);
                }

                ProfilerShort.BeginNextBlock("Lights");
                MyGpuProfiler.IC_BeginBlockAlways("Lights");
                if (m_debugOverrides.Lighting)
                {
                    MyLightRendering.Render(postProcessedShadows);
                }
                MyGpuProfiler.IC_EndBlockAlways();
                postProcessedShadows.Release();

                if (MyRender11.DebugOverrides.Flares)
                {
                    MyLightRendering.DrawFlares();
                }
            }
            MyStereoRender.RenderRegion = MyStereoRegion.FULLSCREEN;
            MyGpuProfiler.IC_EndBlock();

            // Rendering for VR is solved inside of Transparent rendering
            ProfilerShort.BeginNextBlock("Transparent Pass");
            MyGpuProfiler.IC_BeginBlockAlways("TransparentPass");
            if (m_debugOverrides.Transparent)
            {
                MyTransparentRendering.Render();
            }
            MyGpuProfiler.IC_EndBlockAlways();

            ProfilerShort.BeginNextBlock("PostProcess");
            MyGpuProfiler.IC_BeginBlockAlways("PostProcess");
            MyGpuProfiler.IC_BeginBlock("Luminance reduction");
            IBorrowedUavTexture avgLum = null;

            if (MyRender11.Postprocess.EnableEyeAdaptation)
            {
                if (m_resetEyeAdaptation)
                {
                    MyLuminanceAverage.Reset();
                    m_resetEyeAdaptation = false;
                }

                avgLum = MyLuminanceAverage.Run(MyGBuffer.Main.LBuffer);
            }
            else
            {
                avgLum = MyLuminanceAverage.Skip();
            }

            MyGpuProfiler.IC_EndBlock();

            IBorrowedUavTexture histogram = null;
            if (MyRender11.Settings.DisplayHistogram)
            {
                histogram = MyHdrDebugTools.CreateHistogram(MyGBuffer.Main.LBuffer, MyGBuffer.Main.SamplesCount);
            }
            if (MyRender11.Settings.DisplayHdrIntensity)
            {
                MyHdrDebugTools.DisplayHdrIntensity(MyGBuffer.Main.LBuffer);
            }

            MyGpuProfiler.IC_BeginBlock("Bloom");
            IBorrowedUavTexture bloom;
            if (m_debugOverrides.Postprocessing && m_debugOverrides.Bloom)
            {
                bloom = MyBloom.Run(MyGBuffer.Main.LBuffer, MyGBuffer.Main.GBuffer2,
                                    MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);
            }
            else
            {
                bloom = MyManagers.RwTexturesPool.BorrowUav("bloom_EightScreenUavHDR", MyRender11.ResolutionI.X / 8, MyRender11.ResolutionI.Y / 8, MyGBuffer.LBufferFormat);
                MyRender11.RC.ClearRtv(bloom, Color4.Black);
            }
            MyGpuProfiler.IC_EndBlock();


            MyGpuProfiler.IC_BeginBlock("Tone mapping");
            IBorrowedUavTexture tonemapped = MyToneMapping.Run(MyGBuffer.Main.LBuffer, avgLum, bloom, Postprocess.EnableTonemapping && m_debugOverrides.Postprocessing && m_debugOverrides.Tonemapping);
            bloom.Release();
            MyGpuProfiler.IC_EndBlock();

            IRtvTexture renderedImage;

            IBorrowedCustomTexture rgba8_0 = null;
            bool fxaa = MyRender11.FxaaEnabled;
            if (fxaa)
            {
                rgba8_0 = MyManagers.RwTexturesPool.BorrowCustom("MyRender11.Rgb8_0");
                MyGpuProfiler.IC_BeginBlock("FXAA");
                MyFXAA.Run(rgba8_0.Linear, tonemapped);
                MyGpuProfiler.IC_EndBlock();

                renderedImage = rgba8_0.SRgb;
            }
            else
            {
                renderedImage = tonemapped;
            }
            ProfilerShort.Begin("Outline");
            if (MyOutline.AnyOutline())
            {
                IBorrowedRtvTexture outlined = MyOutline.Run();

                MyGpuProfiler.IC_BeginBlock("Outline Blending");
                ProfilerShort.Begin("Outline Blending");
                if (fxaa)
                {
                    MyBlendTargets.RunWithStencil(
                        rgba8_0.SRgb,
                        outlined,
                        MyBlendStateManager.BlendAdditive,
                        MyDepthStencilStateManager.TestOutlineMeshStencil,
                        0x40);
                    MyBlendTargets.RunWithStencil(
                        rgba8_0.SRgb,
                        outlined,
                        MyBlendStateManager.BlendTransparent,
                        MyDepthStencilStateManager.TestHighlightMeshStencil,
                        0x40);
                }
                else
                {
                    if (MyRender11.MultisamplingEnabled)
                    {
                        MyBlendTargets.RunWithPixelStencilTest(tonemapped, outlined, MyBlendStateManager.BlendAdditive);
                        MyBlendTargets.RunWithPixelStencilTest(tonemapped, outlined, MyBlendStateManager.BlendTransparent, true);
                    }
                    else
                    {
                        MyBlendTargets.RunWithStencil(tonemapped, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestOutlineMeshStencil, 0x40);
                        MyBlendTargets.RunWithStencil(tonemapped, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightMeshStencil, 0x40);
                    }
                }
                ProfilerShort.End();
                MyGpuProfiler.IC_EndBlock();

                outlined.Release();
            }
            ProfilerShort.End();

            if (renderTarget != null)
            {
                MyCopyToRT.Run(renderTarget, renderedImage);
            }

            if (MyRender11.Settings.DisplayHistogram)
            {
                if (renderTarget != null && avgLum != null)
                {
                    MyHdrDebugTools.DisplayHistogram(renderTarget, avgLum, histogram);
                }
            }
            MyGpuProfiler.IC_EndBlockAlways();
            ProfilerShort.End();

            if (rgba8_0 != null)
            {
                rgba8_0.Release();
            }
            if (histogram != null)
            {
                histogram.Release();
            }
            avgLum.Release();
            tonemapped.Release();

            // HOTFIX: MyDebugTextureDisplay uses borrowed textures. If we place MyDebugTextureDisplay to the different location, we will have problem with borrowed textures (comment by Michal)
            ProfilerShort.Begin("MyDebugTextureDisplay.Draw");
            MyGpuProfiler.IC_BeginBlock("MyDebugTextureDisplay.Draw");
            MyDebugTextureDisplay.Draw(MyRender11.Backbuffer);
            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();

            return(renderedImage);
        }
        internal static unsafe void Draw(IRtvBindable renderTarget, IDepthStencil depth)
        {
            RC.SetScreenViewport();
            RC.SetPrimitiveTopology(PrimitiveTopology.LineList);
            RC.SetInputLayout(m_inputLayout);

            RC.SetRasterizerState(MyRasterizerStateManager.LinesRasterizerState);

            RC.VertexShader.Set(m_vs);
            RC.PixelShader.Set(m_ps);
            RC.SetBlendState(MyBlendStateManager.BlendAlphaPremult);

            RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);

            CheckBufferSize(m_vertices.Count);
            RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride);

            RC.SetRtv(depth, MyDepthStencilAccess.ReadOnly, renderTarget);

            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);

            if (m_batches.Count > 0)
            {
                var mapping = MyMapping.MapDiscard(m_VB.Buffer);
                mapping.WriteAndPosition(m_vertices.GetInternalArray(), 0, m_vertices.Count);
                mapping.Unmap();

                Matrix prevMatrix = Matrix.Zero;
                foreach (var batch in m_batches)
                {
                    Matrix matrix;
                    if (batch.CustomViewProjection.HasValue)
                    {
                        matrix = batch.CustomViewProjection.Value;
                    }
                    else
                    {
                        matrix = MyRender11.Environment.Matrices.ViewProjectionAt0;
                    }

                    if (prevMatrix != matrix)
                    {
                        prevMatrix = matrix;
                        var transpose = Matrix.Transpose(matrix);

                        mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants);
                        mapping.WriteAndPosition(ref transpose);
                        mapping.Unmap();
                    }

                    if (batch.IgnoreDepth)
                    {
                        RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
                    }
                    else
                    {
                        RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
                    }

                    RC.Draw(batch.VertexCount, batch.StartVertex);
                }
            }

            RC.SetDepthStencilState(null);
            RC.SetRasterizerState(null);

            m_vertices.Clear();

            foreach (var batch in m_batches)
            {
                m_batchesPool.Deallocate(batch);
            }
            m_batches.Clear();
        }
Esempio n. 49
0
        internal static void Draw(IRtvBindable renderTarget, IRtvTexture ambientOcclusion)
        {
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.SetRtv(renderTarget);
            RC.PixelShader.SetSrvs(0, MyGBuffer.Main);

            RC.SetBlendState(null);

            if (MyRender11.Settings.DisplayGbufferColor)
            {
                RC.PixelShader.Set(m_baseColorShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAlbedo)
            {
                RC.PixelShader.Set(m_albedoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormal)
            {
                RC.PixelShader.Set(m_normalShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormalView)
            {
                RC.PixelShader.Set(m_normalViewShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferGlossiness)
            {
                RC.PixelShader.Set(m_glossinessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferMetalness)
            {
                RC.PixelShader.Set(m_metalnessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAO)
            {
                RC.PixelShader.Set(m_aoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEmissive)
            {
                RC.PixelShader.Set(m_emissiveShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientDiffuse)
            {
                RC.PixelShader.Set(m_ambientDiffuseShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientSpecular)
            {
                RC.PixelShader.Set(m_ambientSpecularShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEdgeMask)
            {
                RC.PixelShader.Set(m_edgeDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayShadowsWithDebug)
            {
                RC.PixelShader.Set(m_shadowsDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayNDotL)
            {
                RC.PixelShader.Set(m_NDotLShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferLOD)
            {
                RC.PixelShader.Set(m_LODShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayDepth)
            {
                RC.PixelShader.Set(m_depthShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayStencil)
            {
                RC.PixelShader.Set(m_stencilShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAO)
            {
                RC.PixelShader.SetSrv(0, ambientOcclusion);
                RC.PixelShader.SetSampler(0, MySamplerStateManager.Linear);
                RC.PixelShader.Set(m_rtShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEnvProbe)
            {
                DrawEnvProbe();
            }

            //DrawEnvProbe();
            //DrawAtmosphereTransmittance(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);
            //DrawAtmosphereInscatter(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);

            if (MyRender11.Settings.DrawCascadeTextures)
            {
                //DrawDepthArrayTexture(MyManagers.Shadow.GetCsmForGbuffer(), 100, 100, 200);
                DrawDepthArrayTexture(MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray, 100, 100, 200);
                if (MyScene.SeparateGeometry)
                {
                    DrawDepthArrayTexture(MyRender11.StaticShadows.ShadowCascades.CascadeShadowmapArray, 100, 300, 200);
                    DrawDepthArrayTexture(MyShadowCascades.CombineShadowmapArray, 100, 500, 200);
                }
            }

            if (MyRender11.Settings.DisplayIDs || MyRender11.Settings.DisplayAabbs)
            {
                DrawHierarchyDebug();
            }

            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                foreach (var light in MyLightRendering.VisiblePointlights)
                {
                    batch.AddSphereRing(new BoundingSphere(light.PointPosition, 0.5f), Color.White, Matrix.Identity);
                }
                batch.Commit();
            }

            // draw terrain lods
            if (MyRender11.Settings.DebugRenderClipmapCells)
            {
                //var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => (MyMeshes.IsVoxelMesh(x.Mesh))))
                //{
                //    if (renderable.IsVisible)
                //    {
                //        if (renderable.m_lod >= LOD_COLORS.Length)
                //            return;

                //        BoundingBox bb = new BoundingBox(renderable.m_owner.Aabb.Min - MyRender11.Environment.CameraPosition,renderable.m_owner.Aabb.Max - MyRender11.Environment.CameraPosition);

                //        batch.AddBoundingBox(bb, new Color(LOD_COLORS[renderable.m_voxelLod]));


                //        if (renderable.m_lods != null && renderable.m_voxelLod != renderable.m_lods[0].RenderableProxies[0].ObjectData.CustomAlpha)
                //        {

                //        }
                //    }
                //}

                //batch.Commit();

                MyClipmap.DebugDrawClipmaps();
            }

            if (MyRender11.Settings.EnableVoxelMerging && MyRender11.Settings.DebugRenderMergedCells)
                MyClipmap.DebugDrawMergedCells();

            //if(true)
            //{
            //    var batch = MyLinesRenderer.CreateBatch();

            //    foreach(var id in MyLights.DirtySpotlights)
            //    {
            //        var info = MyLights.Spotlights[id.Index];

            //        if(info.ApertureCos > 0)
            //        {
            //            var D = info.Direction * info.Range;
            //            //batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            //var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range).Transform(Matrix.CreateLookAt(MyLights.Lights.Data[id.Index].Position, info.Direction, info.Up));


            //            //batch.AddBoundingBox(bb, Color.Green);

            //            batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range, MyLights.Lights.Data[id.Index].Position, info.Up);
            //            batch.AddBoundingBox(bb, Color.Green);
            //        } 
            //    }



            //    batch.Commit();
            //}

            // draw lods
            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => ((x.GetMesh() as MyVoxelMesh) == null)))
                //{

                //    if (renderable.CurrentLodNum >= LOD_COLORS.Length || renderable.m_lods.Length == 1)
                //        continue;

                //    batch.AddBoundingBox(renderable.m_owner.Aabb, new Color(LOD_COLORS[renderable.CurrentLodNum]));
                //}

                batch.Commit();
            }
        }
Esempio n. 50
0
        // viewport, render target
        internal unsafe static void Draw(IRtvBindable rtv, MyViewport viewport, IBlendState blendstate = null)
        {
            if (StackTop.m_internalBatch.Texture != null && StackTop.m_internalBatch.Count > 0)
                StackTop.m_internalBatch.Commit();
            StackTop.m_internalBatch = new MySpritesBatch();

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);

            RC.SetInputLayout(m_inputLayout);
            //RC.SetScreenViewport();
            RC.SetViewport(viewport.OffsetX, viewport.OffsetY, viewport.Width, viewport.Height);

            RC.VertexShader.Set(m_vs);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.GetObjectCB(64));
            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            //RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, MyRender11.Backbuffer);
            // to reset state
            RC.SetRtv(rtv);

            RC.SetBlendState(blendstate == null ? MyBlendStateManager.BlendAlphaPremult : blendstate);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil, 0);

            CheckBufferSize(StackTop.m_instances.Count);
            RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride);

            var mapping = MyMapping.MapDiscard(m_VB.Buffer);
            for (int i = 0; i < StackTop.m_instances.Count; i++)
            {
                var helper = StackTop.m_instances[i];
                mapping.WriteAndPosition(ref helper);
            }
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(64));
            var viewportSize = new Vector2(viewport.Width, viewport.Height);
            mapping.WriteAndPosition(ref viewportSize);
            mapping.Unmap();

            foreach (var batch in StackTop.m_batches)
            {
                if(batch.ScissorRectangle.HasValue)
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.ScissorTestRasterizerState);

                    var scissor = batch.ScissorRectangle.Value;
                    RC.SetScissorRectangle((int)scissor.X, (int)scissor.Y, (int)(scissor.X + scissor.Width), (int)(scissor.Y + scissor.Height));
                }
                else
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
                }

                RC.PixelShader.SetSrv(0, batch.Texture);
                RC.DrawInstanced(4, batch.Count, 0, batch.Start);
            }

            RC.SetBlendState(null);
            RC.SetRasterizerState(null);
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            StackTop.m_instances.Clear();
            StackTop.m_batches.Clear();
        }
Esempio n. 51
0
 internal static void RunFullscreenSampleFreq(IRtvBindable RT)
 {
     Debug.Assert(MyRender11.MultisamplingEnabled);
     RC.SetDepthStencilState(MyDepthStencilStateManager.TestEdgeStencil, 0x80);
     RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, RT);
     DrawFullscreenQuad();
     RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
 }
Esempio n. 52
0
 private static void BlendHighlight(IRtvBindable target, ISrvBindable outlined, ICustomTexture fxaaTarget, IDepthStencil depthStencilCopy)
 {
     MyGpuProfiler.IC_BeginBlock("Highlight Blending");
     ProfilerShort.Begin("Highlight Blending");
     if (fxaaTarget != null)
     {
         MyBlendTargets.RunWithStencil(
             fxaaTarget.SRgb,
             outlined,
             MyBlendStateManager.BlendAdditive,
             MyDepthStencilStateManager.TestHighlightOuterStencil,
             HIGHLIGHT_STENCIL_MASK,
             depthStencilCopy);
         MyBlendTargets.RunWithStencil(
             fxaaTarget.SRgb,
             outlined,
             MyBlendStateManager.BlendTransparent,
             MyDepthStencilStateManager.TestHighlightInnerStencil,
             HIGHLIGHT_STENCIL_MASK,
             depthStencilCopy);
     }
     else
     {
         if (MyRender11.MultisamplingEnabled)
         {
             MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendAdditive, false, depthStencilCopy);
             MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendTransparent, true, depthStencilCopy);
         }
         else
         {
             MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendAdditive,
                 MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK,
                 depthStencilCopy);
             MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendTransparent,
                 MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK,
                 depthStencilCopy);
         }
     }
     ProfilerShort.End();
     MyGpuProfiler.IC_EndBlock();
 }
Esempio n. 53
0
 public void CopyRedToAll(IRtvBindable output, ISrvTexture source)
 {
     m_postprocessRedToAll.CopyRedToAll(output, source);
 }
Esempio n. 54
0
        // viewport, render target
        internal unsafe static void Draw(IRtvBindable rtv, MyViewport viewport, IBlendState blendstate = null)
        {
            if (StackTop.m_internalBatch.Texture != null && StackTop.m_internalBatch.Count > 0)
            {
                StackTop.m_internalBatch.Commit();
            }
            StackTop.m_internalBatch = new MySpritesBatch();

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);

            RC.SetInputLayout(m_inputLayout);
            //RC.SetScreenViewport();
            RC.SetViewport(viewport.OffsetX, viewport.OffsetY, viewport.Width, viewport.Height);

            RC.VertexShader.Set(m_vs);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.GetObjectCB(64));
            RC.PixelShader.Set(m_ps);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            //RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, MyRender11.Backbuffer);
            // to reset state
            RC.SetRtv(rtv);

            RC.SetBlendState(blendstate == null ? MyBlendStateManager.BlendAlphaPremult : blendstate);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil, 0);

            CheckBufferSize(StackTop.m_instances.Count);
            RC.SetVertexBuffer(0, m_VB);

            var mapping = MyMapping.MapDiscard(m_VB);

            for (int i = 0; i < StackTop.m_instances.Count; i++)
            {
                var helper = StackTop.m_instances[i];
                mapping.WriteAndPosition(ref helper);
            }
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(64));
            var viewportSize = new Vector2(viewport.Width, viewport.Height);

            mapping.WriteAndPosition(ref viewportSize);
            mapping.Unmap();

            foreach (var batch in StackTop.m_batches)
            {
                if (batch.ScissorRectangle.HasValue)
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.ScissorTestRasterizerState);

                    var scissor = batch.ScissorRectangle.Value;
                    RC.SetScissorRectangle((int)scissor.X, (int)scissor.Y, (int)(scissor.X + scissor.Width), (int)(scissor.Y + scissor.Height));
                }
                else
                {
                    RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
                }

                RC.PixelShader.SetSrv(0, batch.Texture);
                RC.DrawInstanced(4, batch.Count, 0, batch.Start);
            }

            RC.SetBlendState(null);
            RC.SetRasterizerState(null);
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            StackTop.m_instances.Clear();
            StackTop.m_batches.Clear();
        }
Esempio n. 55
0
 static void DrawLinearDepthPS(ISrvBindable resolvedDepth, IRtvBindable rtv, MyViewport viewport)
 {
     RC.PixelShader.Set(m_linearizeDepthPS);
     //RC.SetRtv(m_fullResViewDepthTarget);
     RC.SetRtv(rtv);
     RC.PixelShader.SetSrv(0, resolvedDepth);
     MyScreenPass.DrawFullscreenQuad(viewport);
     RC.SetRtv(null);
 }
Esempio n. 56
0
        /// <param name="clearColor">Color used to clear render targets. Defaults to black</param>
        internal static void Run(IRtvBindable renderTarget, IRtvTexture intermediate, ISrvBindable initialResourceView,
            int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f,
            IDepthStencilState depthStencilState = null, int stencilRef = 0x0, Color4 clearColor = default(Color4),
            float depthDiscardThreshold = 0.0f, MyViewport? viewport = null)
        {
            ProfilerShort.Begin("MyBlur.Run");
            MyGpuProfiler.IC_BeginBlock("MyBlur.Run");
            Debug.Assert(initialResourceView != null);
            Debug.Assert(intermediate != null);
            Debug.Assert(renderTarget != null);

            int shaderKey = InitShaders(densityFunctionType, maxOffset, depthDiscardThreshold);

            RC.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer);

            BlurConstants constants = new BlurConstants
            {
                DistributionWeight = WeightParameter,
                StencilRef = stencilRef,
            };
            var mapping = MyMapping.MapDiscard(m_blurConstantBuffer);
            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            // Horizontal pass
            // NOTE: DepthStencilState is not used here because the resulted target
            // would not be usable to perform vertical pass. DepthStencil is stil
            // bindinded as SRV since it is sampled in the shader 
            RC.ClearRtv(intermediate, clearColor);
            RC.SetRtv(intermediate);
            RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
            RC.PixelShader.SetSrv(4, MyGBuffer.Main.DepthStencil.SrvStencil);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.PixelShader.SetSrv(5, initialResourceView);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item1);
            MyScreenPass.DrawFullscreenQuad(viewport);
            RC.PixelShader.SetSrv(5, null);

            // Vertical pass
            RC.ClearRtv(renderTarget, clearColor);
            if (depthStencilState == null)
            {
                RC.SetRtv(renderTarget);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilRef);
                RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget);
            }

            RC.PixelShader.SetSrv(5, intermediate);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item2);
            MyScreenPass.DrawFullscreenQuad(viewport);

            RC.PixelShader.SetSrv(0, null);
            RC.PixelShader.SetSrv(4, null);
            RC.PixelShader.SetSrv(5, null);
            RC.SetRtv(null);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
Esempio n. 57
0
        static void DrawDeinterleavedDepth(MyViewport viewport)
        {
            var qViewport = GetQuarterViewport(viewport);
            RC.PixelShader.Set(m_deinterleaveDepthPS);
            RC.PixelShader.SetSrv(0, m_fullResViewDepthTarget);

            var rtvs = new IRtvBindable[MAX_NUM_MRTS];
            for (int sliceIndex = 0; sliceIndex < NUM_SLICES; sliceIndex += MAX_NUM_MRTS)
            {
                for (int i = 0; i < MAX_NUM_MRTS; i++)
                    rtvs[i] = m_quarterResViewDepthTextureArray.SubresourceRtv(sliceIndex + i);
                RC.SetRtvs(rtvs);
                RC.PixelShader.SetConstantBuffer(1, m_perPassCBs[sliceIndex]);

                MyScreenPass.DrawFullscreenQuad(qViewport);
            }
        }
Esempio n. 58
0
 static void Resolve(bool blur, IRtvBindable dst, MyViewport viewport)
 {
     RC.SetRtv(dst);
     RC.PixelShader.SetSrv(0, m_quarterResAOTextureArray);
     if (blur)
     {
         RC.PixelShader.Set(m_reinterleaveAOPS_PreBlur);
         RC.PixelShader.SetSrv(1, m_fullResViewDepthTarget);
     }
     else
     {
         RC.PixelShader.Set(m_reinterleaveAOPS);
     }
     RC.PixelShader.SetSamplers(0, MySamplerStateManager.PointHBAOClamp);
     MyScreenPass.DrawFullscreenQuad(viewport);
 }
Esempio n. 59
0
 private static void DrawSprites(IRtvBindable texture, MyViewport viewPort)
 {
     GetRenderProfiler().StartProfilingBlock("MySpritesRenderer.Draw");
     MyStatsUpdater.Timestamps.Update(ref MyStatsUpdater.Timestamps.PreDrawSprites_Draw);
     MyGpuProfiler.IC_BeginBlock("SpriteRenderer");
     MySpritesRenderer.Draw(texture, viewPort);
     MyGpuProfiler.IC_EndBlock();
     MyStatsUpdater.Timestamps.Update(ref MyStatsUpdater.Timestamps.PostDrawSprites_Draw);
     GetRenderProfiler().EndProfilingBlock();
 }