Пример #1
0
        internal static void CreateScreenResources()
        {
            var width   = m_resolution.X;
            var height  = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            if (MyGBuffer.Main == null)
            {
                MyGBuffer.Main = new MyGBuffer();
            }
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_resolvedLight = new MyRenderTarget(width, height, Format.R11G11B10_Float, 1, 0);
            m_reduce0       = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, Format.R11G11B10_Float);

            m_localLum = new MyUnorderedAccessTexture(
                (width + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                (height + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                Format.R32_Float);

            m_div2   = new MyUnorderedAccessTexture(width / 2, height / 2, Format.R11G11B10_Float);
            m_div4   = new MyUnorderedAccessTexture(width / 4, height / 4, Format.R11G11B10_Float);
            m_div8   = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);
            m_div8_1 = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView
            });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_rgba8_2 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            if (samples > 1)
            {
                m_rgba8_ms = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, samples, 0);
            }
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32G32_Float);

            Debug.Assert(m_shadowsHelper == RwTexId.NULL);
            m_shadowsHelper  = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather");
            m_shadowsHelper1 = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather 2");

            m_gbuffer1Copy = MyRwTextures.CreateScratch2D(width, height, Format.R8G8B8A8_UNorm, samples, 0, "gbuffer 1 copy");
        }
Пример #2
0
        internal static void CreateScreenResources()
        {
            var width   = m_resolution.X;
            var height  = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            MyUtils.Init(ref MyGBuffer.Main);
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_reduce0 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, MyGBuffer.LBufferFormat);

            m_transparencyAccum    = new MyUnorderedAccessTexture(width, height, Format.R16G16B16A16_Float);
            m_transparencyCoverage = new MyUnorderedAccessTexture(width, height, Format.R8_UNorm);

            HalfScreenUavHDR         = new MyUnorderedAccessTexture(width / 2, height / 2, MyGBuffer.LBufferFormat);
            QuarterScreenUavHDR      = new MyUnorderedAccessTexture(width / 4, height / 4, MyGBuffer.LBufferFormat);
            EighthScreenUavHDR       = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);
            EighthScreenUavHDRHelper = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView
            });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_rgba8_2 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            if (samples > 1)
            {
                m_rgba8_ms = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, samples, 0);
            }
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32G32_Float);

            Debug.Assert(PostProcessedShadows == RwTexId.NULL);
            Debug.Assert(CascadesHelper == RwTexId.NULL);
            PostProcessedShadows = MyRwTextures.CreateUavRenderTarget(width, height, Format.R8_UNorm);
            CascadesHelper       = MyRwTextures.CreateRenderTarget(width, height, Format.R8_UNorm);

            m_gbuffer1Copy = MyRwTextures.CreateScratch2D(width, height, Format.R8G8B8A8_UNorm, samples, 0, "gbuffer 1 copy");
        }
        internal static void CreateScreenResources()
        {
            var width   = m_resolution.X;
            var height  = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            MyUtils.Init(ref MyGBuffer.Main);
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            MyHBAO.InitScreenResources();
        }
Пример #4
0
        // Returns the final image and copies it to renderTarget if non-null
        private static IRtvTexture DrawGameScene(IRtvBindable renderTarget, out IBorrowedRtvTexture debugAmbientOcclusion)
        {
            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();

            IBorrowedRtvTexture gbuffer1Copy = MyGBuffer.Main.GetGbuffer1CopyRtv();

            ProfilerShort.Begin("Render decals - Opaque");
            MyGpuProfiler.IC_BeginBlock("Render decals - Opaque");
            MyScreenDecals.Draw(gbuffer1Copy, false);
            MyGpuProfiler.IC_EndBlock();

            IBorrowedDepthStencilTexture depthStencilCopy = null; // Highlights need the depth state before foliage
            if (MyHighlight.HasHighlights)
            {
                depthStencilCopy = MyGBuffer.Main.GetDepthStencilCopyRtv();
            }

            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();

            IBorrowedRtvTexture ambientOcclusionRtv = MyScreenDependants.GetAmbientOcclusionRtv();
            debugAmbientOcclusion = ambientOcclusionRtv; // Pass the texture to the outside

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

                MyGBuffer.Main.ResolveMultisample();

                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 && RenderSettings.AmbientOcclusionEnabled &&
                    m_debugOverrides.Postprocessing && m_debugOverrides.SSAO)
                {
                    ProfilerShort.BeginNextBlock("SSAO");
                    MyGpuProfiler.IC_BeginBlockAlways("SSAO");
                    MySSAO.Run(ambientOcclusionRtv, MyGBuffer.Main);

                    if (MySSAO.Params.UseBlur)
                    {
                        IBorrowedRtvTexture ambientOcclusionHelper = MyScreenDependants.GetAmbientOcclusionHelper();
                        MyBlur.Run(ambientOcclusionRtv, ambientOcclusionHelper, ambientOcclusionRtv, clearColor: Color4.White);
                        ambientOcclusionHelper.Release();
                    }
                    MyGpuProfiler.IC_EndBlockAlways();
                }
                else if (MyHBAO.Params.Enabled && RenderSettings.AmbientOcclusionEnabled &&
                         m_debugOverrides.Postprocessing && m_debugOverrides.SSAO)
                {
                    ProfilerShort.BeginNextBlock("HBAO");
                    MyGpuProfiler.IC_BeginBlock("HBAO");
                    MyHBAO.Run(ambientOcclusionRtv, MyGBuffer.Main);
                    MyGpuProfiler.IC_EndBlock();
                }
                else
                {
                    MyRender11.RC.ClearRtv(ambientOcclusionRtv, Color4.White);
                }

                ProfilerShort.BeginNextBlock("Lights");
                MyGpuProfiler.IC_BeginBlockAlways("Lights");
                if (m_debugOverrides.Lighting)
                {
                    MyLightRendering.Render(postProcessedShadows, ambientOcclusionRtv);
                }
                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(gbuffer1Copy);
            }
            MyGpuProfiler.IC_EndBlockAlways();

            gbuffer1Copy.Release();

            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, MyGBuffer.Main.ResolvedDepthStencil.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 fxaaTarget = null;
            bool fxaa = MyRender11.FxaaEnabled;
            if (fxaa)
            {
                fxaaTarget = MyManagers.RwTexturesPool.BorrowCustom("MyRender11.FXAA.Rgb8");
                MyGpuProfiler.IC_BeginBlock("FXAA");
                MyFXAA.Run(fxaaTarget.Linear, tonemapped);
                MyGpuProfiler.IC_EndBlock();

                renderedImage = fxaaTarget.SRgb;
            }
            else
            {
                renderedImage = tonemapped;
            }


            ProfilerShort.Begin("Outline");
            MyHighlight.Run(renderedImage, fxaaTarget, depthStencilCopy);
            ProfilerShort.End();

            if (depthStencilCopy != null)
            {
                depthStencilCopy.Release();
            }

            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 (fxaaTarget != null)
            {
                fxaaTarget.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);
        }