internal static void Render(ISrvTexture postProcessedShadows)
        {
            MyLights.Update();

            MyGpuProfiler.IC_BeginBlock("Map lights to tiles");
            if (MyRender11.DebugOverrides.PointLights)
            {
                PreparePointLights();
            }
            MyGpuProfiler.IC_BeginNextBlock("Apply point lights");

            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            if (!MyStereoRender.Enable)
            {
                RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
                RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
                MyStereoRender.PSBindRawCB_FrameConstants(RC);
            }

            RC.PixelShader.SetSrvs(0, MyGBuffer.Main);
            RC.AllShaderStages.SetRawSrv(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer.Srv);
            RC.SetBlendState(MyBlendStateManager.BlendAdditive);
            if (!MyStereoRender.Enable)
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            }
            else
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.StereoIgnoreDepthStencil);
            }
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            if (MyRender11.DebugOverrides.PointLights)
            {
                RenderPointlightsTiled();
            }

            MyGpuProfiler.IC_BeginNextBlock("Apply spotlights");
            if (MyRender11.DebugOverrides.SpotLights)
            {
                RenderSpotlights();
            }

            MyGpuProfiler.IC_BeginNextBlock("Apply directional light");
            if (MyRender11.DebugOverrides.EnvLight)
            {
                RenderDirectionalEnvironmentLight(postProcessedShadows);
            }
            MyGpuProfiler.IC_EndBlock();

            // Because of BindGBufferForRead:
            RC.AllShaderStages.SetSrv(0, null);
            RC.AllShaderStages.SetSrv(1, null);
            RC.AllShaderStages.SetSrv(2, null);
            RC.AllShaderStages.SetSrv(3, null);
            RC.AllShaderStages.SetSrv(4, null);
            RC.SetBlendState(null);
            RC.SetRtv(null);
        }
        internal static void Render()
        {
            IBorrowedUavTexture accumTarget    = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.AccumTarget", Format.R16G16B16A16_Float);
            IBorrowedUavTexture coverageTarget = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.CoverageTarget", Format.R16_UNorm);

            ProfilerShort.Begin("Atmosphere");
            MyGpuProfiler.IC_BeginBlock("Atmosphere");
            if (MyRender11.DebugOverrides.Atmosphere)
            {
                MyAtmosphereRenderer.Render();
            }

            ProfilerShort.BeginNextBlock("Clouds");
            MyGpuProfiler.IC_BeginNextBlock("Clouds");
            if (MyRender11.DebugOverrides.Clouds)
            {
                MyCloudRenderer.Render();
            }
            MyGpuProfiler.IC_EndBlock();

            // setup weighted blended OIT targets + blend states
            SetupTargets(accumTarget, coverageTarget, true);

            IDepthStencil depthResource;

            if (MyRender11.MultisamplingEnabled)
            {
                depthResource = MyScreenDependants.m_resolvedDepth;
            }
            else
            {
                depthResource = MyGBuffer.Main.DepthStencil;
            }

            m_windowsWithDecals.Clear();
            ProfilerShort.BeginNextBlock("Billboards");
            MyGpuProfiler.IC_BeginBlock("Billboards");
            bool resetBindings = MyBillboardRenderer.Gather(HandleWindow);

            if (resetBindings)
            {
                SetupTargets(accumTarget, coverageTarget, false);
            }

            MyBillboardRenderer.Render(depthResource.SrvDepth);

            ProfilerShort.BeginNextBlock("GPU Particles");
            MyGpuProfiler.IC_BeginNextBlock("GPU Particles");
            if (MyRender11.DebugOverrides.GPUParticles)
            {
                MyGPUParticleRenderer.Run(depthResource.SrvDepth);
            }
            MyGpuProfiler.IC_EndBlock();

            // Render decals on transparent surfaces in 2 steps: first far, second proximity
            float intervalMax = MyScreenDecals.VISIBLE_DECALS_SQ_TH;

            for (int it = 0; it < m_distances.Length; it++)
            {
                float intervalMin = m_distances[it];

                ProfilerShort.BeginNextBlock("Billboards - Depth Only");
                MyGpuProfiler.IC_BeginBlock("Billboards - Depth Only");
                bool windowsFound = MyBillboardRenderer.RenderWindowsDepthOnly(depthResource, MyGlobalResources.Gbuffer1Copy, intervalMin, intervalMax);
                MyGpuProfiler.IC_EndBlock();

                if (windowsFound)
                {
                    SetupTargets(accumTarget, coverageTarget, false);

                    ProfilerShort.BeginNextBlock("Render decals - Transparent");
                    MyGpuProfiler.IC_BeginBlock("Render decals - Transparent");
                    MyScreenDecals.Draw(true, m_windowsWithDecals);
                    MyGpuProfiler.IC_EndBlock();
                }

                intervalMax = intervalMin;
            }

            if (IsUsedOverlappingHeatMap())
            {
                DisplayOverlappingHeatMap(accumTarget, coverageTarget, MyRender11.Settings.DisplayTransparencyHeatMapInGrayscale);
            }

            MyGpuProfiler.IC_BeginBlock("OIT Resolve");
            // resolve weighted blended OIT in  accum / coverage to LBuffer
            if (MyRender11.DebugOverrides.OIT)
            {
                ResolveOIT(accumTarget, coverageTarget);
            }
            else
            {
                RC.SetRtv(null);
            }
            MyGpuProfiler.IC_EndBlock();

            coverageTarget.Release();
            accumTarget.Release();

            ProfilerShort.End();
        }
Exemplo n.º 3
0
        internal static void Render(IRtvTexture gbuffer1Copy)
        {
            IBorrowedUavTexture accumTarget    = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.AccumTarget", Format.R16G16B16A16_Float);
            IBorrowedUavTexture coverageTarget = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.CoverageTarget", Format.R16_UNorm);

            ProfilerShort.Begin("Atmosphere");
            MyGpuProfiler.IC_BeginBlock("Atmosphere");
            if (MyRender11.DebugOverrides.Atmosphere)
            {
                MyAtmosphereRenderer.RenderGBuffer();
            }

            ProfilerShort.BeginNextBlock("Clouds");
            MyGpuProfiler.IC_BeginNextBlock("Clouds");
            if (MyRender11.DebugOverrides.Clouds)
            {
                MyCloudRenderer.Render();
            }

            var depthResource = MyGBuffer.Main.ResolvedDepthStencil;

            // setup weighted blended OIT targets + blend states
            if (MyRender11.Settings.DrawBillboards)
            {
                ProfilerShort.BeginNextBlock("Billboards");
                MyGpuProfiler.IC_BeginNextBlock("Billboards");
                MyBillboardRenderer.Gather();

                MyBillboardRenderer.RenderAdditveBottom(depthResource.SrvDepth);

                SetupTargets(accumTarget, coverageTarget, true);

                MyBillboardRenderer.RenderStandard(depthResource.SrvDepth);
            }
            else
            {
                SetupTargets(accumTarget, coverageTarget, true);
            }

            ProfilerShort.BeginNextBlock("GPU Particles");
            MyGpuProfiler.IC_BeginNextBlock("GPU Particles");
            if (MyRender11.DebugOverrides.GPUParticles)
            {
                MyGPUParticleRenderer.Run(depthResource.SrvDepth, MyGBuffer.Main.GBuffer1);
            }

            // Render decals on transparent surfaces in 2 steps: first far, second proximity
            if (MyRender11.Settings.DrawGlass)
            {
                ProfilerShort.BeginNextBlock("Static glass");
                MyGpuProfiler.IC_BeginNextBlock("Static glass");
                m_glassWithDecals.Clear();
                MyStaticGlassRenderer.Render(HandleGlass);

                float intervalMax = MyScreenDecals.VISIBLE_DECALS_SQ_TH;
                for (int it = 0; it < m_distances.Length; it++)
                {
                    float intervalMin = m_distances[it];

                    ProfilerShort.BeginNextBlock("Glass - Depth Only");
                    MyGpuProfiler.IC_BeginNextBlock("Glass - Depth Only");
                    //TODO: This code should properly render glass decals, that they are visible when looking through window on another window
                    // Anyway, it is italian code and it doesnt work. Solve after Beta
                    bool glassFound = MyStaticGlassRenderer.RenderGlassDepthOnly(depthResource, gbuffer1Copy, intervalMin, intervalMax);

                    // if (glassFound)
                    {
                        SetupTargets(accumTarget, coverageTarget, false);

                        ProfilerShort.BeginNextBlock("Render decals - Transparent");
                        MyGpuProfiler.IC_BeginNextBlock("Render decals - Transparent");
                        MyScreenDecals.Draw(gbuffer1Copy, true /*, m_glassWithDecals*/);
                    }

                    intervalMax = intervalMin;
                }
            }

            if (IsUsedOverlappingHeatMap())
            {
                DisplayOverlappingHeatMap(accumTarget, coverageTarget, MyRender11.Settings.DisplayTransparencyHeatMapInGrayscale);
            }

            MyGpuProfiler.IC_BeginNextBlock("OIT Resolve");
            // resolve weighted blended OIT in  accum / coverage to LBuffer
            if (MyRender11.DebugOverrides.OIT)
            {
                ResolveOIT(accumTarget, coverageTarget);
            }

            ProfilerShort.BeginNextBlock("Billboards");
            MyGpuProfiler.IC_BeginNextBlock("Billboards");
            if (MyRender11.Settings.DrawBillboards)
            {
                MyBillboardRenderer.RenderAdditveTop(depthResource.SrvDepth);
            }

            RC.SetRtv(null);

            MyGpuProfiler.IC_EndBlock();

            coverageTarget.Release();
            accumTarget.Release();

            ProfilerShort.End();
        }