示例#1
0
        private static void Render(ISrvBindable depthRead, MyBucketBatches bucketBatches, bool oit)
        {
            if (!MyRender11.DebugOverrides.BillboardsDynamic && !MyRender11.DebugOverrides.BillboardsStatic)
            {
                return;
            }

            if (m_batches.Count == 0)
            {
                return;
            }

            MyRender11.GetRenderProfiler().StartProfilingBlock("Draw");

            RC.PixelShader.SetSrv(1, depthRead);
            BindResourcesCommon();

            PixelShaderFlags basePsFlags = (MyRender11.Settings.DisplayTransparencyHeatMap ? PixelShaderFlags.DEBUG_UNIFORM_ACCUM : 0) |
                                           ((MyRender11.DebugOverrides.OIT && oit) ? PixelShaderFlags.OIT : 0) |
                                           (depthRead != null ? PixelShaderFlags.SOFT_PARTICLE : 0);

            for (int i = bucketBatches.StartIndex; i < bucketBatches.StartIndex + bucketBatches.Count; i++)
            {
                var ps = m_psBundle[(int)(basePsFlags |
                                          (m_batches[i].Lit ? PixelShaderFlags.LIT_PARTICLE : 0) |
                                          (m_batches[i].AlphaCutout ? PixelShaderFlags.ALPHA_CUTOUT : 0))];
                RC.VertexShader.Set(m_batches[i].Lit ? m_vsLit : m_vs);
                RC.PixelShader.Set(ps);

                ISrvBindable texture = m_batches[i].Texture;
                RC.PixelShader.SetSrv(0, texture);
                if (!MyStereoRender.Enable)
                {
                    RC.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0);
                }
                else
                {
                    MyStereoRender.DrawIndexedBillboards(RC, m_batches[i].Num * 6, m_batches[i].Offset * 6, 0);
                }

                IBorrowedRtvTexture borrowedTexture = texture as IBorrowedRtvTexture;
                if (borrowedTexture != null)
                {
                    borrowedTexture.Release();
                }

                MyStatsUpdater.Passes.DrawBillboards++;
            }

            m_stats.Billboards += m_billboardCountSafe;

            RC.SetRasterizerState(null);
            MyRender11.GatherPassStats(1298737, "Billboards", m_stats);
            MyRender11.GetRenderProfiler().EndProfilingBlock();
        }
示例#2
0
        public IBorrowedUavTexture Evaluate()
        {
            MyRenderProxy.Assert(m_mainCsm.SlicesCount == m_settings.NewData.CascadesCount, "Cascades count incostistency");
            if (m_settings.NewData.DrawVolumes)
            {
                ShadowCore.DrawVolumes();
            }
            ShadowCore.MarkAllCascades(MyGBuffer.Main.DepthStencil, MyRender11.Environment.Matrices.ViewProjectionAt0, m_mainCsm);
            if (m_settings.NewData.DisplayCascadeCoverage)
            {
                IBorrowedRtvTexture target = MyManagers.RwTexturesPool.BorrowRtv("MyShadows.Evaluate.CascadeCoverage", Format.R8G8B8A8_SNorm);
                ShadowCore.DrawCoverage(target, MyGBuffer.Main.DepthStencil);
                MyDebugTextureDisplay.Select(target);
                target.Release();
            }

            if (m_settings.NewData.DisplayHardShadows)
            {
                IBorrowedUavTexture hardShadowed =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.HardShadowed", Format.R8_UNorm);
                ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.HARD, hardShadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings);
                MyDebugTextureDisplay.Select(hardShadowed);
                hardShadowed.Release();
            }

            if (m_settings.NewData.DisplaySimpleShadows)
            {
                IBorrowedUavTexture simpleShadowed =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.SimpleShadowed", Format.R8_UNorm);
                ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.SIMPLE, simpleShadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings);
                MyDebugTextureDisplay.Select(simpleShadowed);
                simpleShadowed.Release();
            }

            IBorrowedUavTexture shadowed =
                MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.Shadowed", Format.R8_UNorm);

            ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.SIMPLE, shadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings);

            if (m_settings.NewData.EnableFXAAOnShadows)
            {
                IBorrowedUavTexture inputForFXAA =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.InputForFXAA", Format.R8G8B8A8_UNorm);
                ShadowCore.CopyRedToAll(inputForFXAA, shadowed);
                IBorrowedUavTexture shadowedWithFXAA =
                    MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.ShadowedWithFXAA", Format.R8G8B8A8_UNorm);
                MyFXAA.Run(shadowedWithFXAA, inputForFXAA);
                shadowed.Release();
                inputForFXAA.Release();
                shadowed = shadowedWithFXAA;
            }
            return(shadowed);
        }
示例#3
0
        public static void DisplayHdrIntensity(ISrvBindable srv)
        {
            RC.PixelShader.Set(m_psDisplayHdrIntensity);
            RC.PixelShader.SetSrv(5, srv);
            RC.SetBlendState(null);
            IBorrowedRtvTexture outTex = MyManagers.RwTexturesPool.BorrowRtv("MyHdrDebugTools.DisplayHdrIntensity.OutTex", srv.Size.X, srv.Size.Y, Format.B8G8R8X8_UNorm);

            MyScreenPass.RunFullscreenPixelFreq(outTex);
            MyDebugTextureDisplay.Select(outTex);

            RC.PixelShader.SetSrv(5, null);
            RC.SetRtvs(MyGBuffer.Main, MyDepthStencilAccess.ReadOnly);
            outTex.Release();
        }
 public static void Deselect()
 {
     m_selRtvTexture = null;
     m_selUavTexture = null;
     if (m_selBorrowedRtvTexture != null)
     {
         m_selBorrowedRtvTexture.Release();
         m_selBorrowedRtvTexture = null;
     }
     if (m_selBorrowedUavTexture != null)
     {
         m_selBorrowedUavTexture.Release();
         m_selBorrowedUavTexture = null;
     }
 }
示例#5
0
 public static void Deselect()
 {
     m_selRtvTexture = null;
     m_selUavTexture = null;
     if (m_selBorrowedRtvTexture != null)
     {
         m_selBorrowedRtvTexture.Release();
         m_selBorrowedRtvTexture = null;
     }
     if (m_selBorrowedUavTexture != null)
     {
         m_selBorrowedUavTexture.Release();
         m_selBorrowedUavTexture = null;
     }
 }
        static void DisplayOverlappingHeatMap(IUavTexture accumTarget, IUavTexture coverageTarget, bool useGrayscale)
        {
            IBorrowedRtvTexture heatMap = MyManagers.RwTexturesPool.BorrowRtv("MyTransparentRendering.HeatMap",
                                                                              Format.R8G8B8A8_UNorm);

            RC.ClearRtv(heatMap, default(RawColor4));

            RC.SetRtv(heatMap);
            RC.PixelShader.SetSrv(0, accumTarget);
            RC.PixelShader.Set(useGrayscale ? m_psOverlappingHeatMapInGrayscale : m_psOverlappingHeatMap);
            RC.SetBlendState(MyBlendStateManager.BlendAdditive);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            MyScreenPass.DrawFullscreenQuad();

            RC.PixelShader.Set(null);
            RC.PixelShader.SetSrv(0, null);
            RC.SetRtv(null);
            SetupOIT(accumTarget, coverageTarget, false);

            MyDebugTextureDisplay.Select(heatMap);
            heatMap.Release();
        }
示例#7
0
        internal unsafe static void Render(ISrvBindable depthRead)
        {
            if (!MyRender11.DebugOverrides.BillboardsDynamic && !MyRender11.DebugOverrides.BillboardsStatic)
            {
                return;
            }

            if (m_batches.Count == 0)
            {
                return;
            }

            MyRender11.GetRenderProfiler().StartProfilingBlock("Draw");
            TransferDataCustomProjections();
            TransferDataBillboards(0, BillboardCountSafe, ref m_arrayDataBillboards);

            RC.PixelShader.SetSrv(1, depthRead);
            BindResourcesCommon();

            for (int i = 0; i < m_batches.Count; i++)
            {
                // first part of batches contain sorted billboards and they read depth
                // second part of batches contain unsorted billboards and they ignore depth
                // switch here:
                if (m_batches[i].Offset == m_sortedCount)
                {
                    //RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst);
                }

                if (MyRender11.Settings.DisplayTransparencyHeatMap)
                {
                    RC.VertexShader.Set(m_vs);
                    RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psDebugUniformAccumOIT : m_psDebugUniformAccum);
                }
                else if (m_batches[i].Lit)
                {
                    RC.VertexShader.Set(m_vsLit);

                    if (m_batches[i].AlphaCutout)
                    {
                        RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psAlphaCutoutAndLitOIT : m_psAlphaCutoutAndLit);
                    }
                    else
                    {
                        RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psLitOIT : m_psLit);
                    }
                }
                else if (m_batches[i].AlphaCutout)
                {
                    RC.VertexShader.Set(m_vs);
                    RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psAlphaCutoutOIT : m_psAlphaCutout);
                }
                else
                {
                    RC.VertexShader.Set(m_vs);
                    RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psOIT : m_ps);
                }

                ISrvBindable texture = m_batches[i].Texture;
                RC.PixelShader.SetSrv(0, texture);
                if (!MyStereoRender.Enable)
                {
                    RC.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0);
                }
                else
                {
                    MyStereoRender.DrawIndexedBillboards(RC, m_batches[i].Num * 6, m_batches[i].Offset * 6, 0);
                }

                IBorrowedRtvTexture borrowedTexture = texture as IBorrowedRtvTexture;
                if (borrowedTexture != null)
                {
                    borrowedTexture.Release();
                }

                MyStatsUpdater.Passes.DrawBillboards++;
            }

            m_stats.Billboards += BillboardCountSafe;

            RC.SetRasterizerState(null);
            MyRender11.GatherStats(m_stats);
            MyRender11.GetRenderProfiler().EndProfilingBlock();
        }
        // 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);
        }
示例#9
0
        internal static void RenderColoredTextures(List <renderColoredTextureProperties> texturesToRender)
        {
            if (texturesToRender.Count == 0)
            {
                return;
            }

            if (!m_initialized)
            {
                Init();
            }

            const int RENDER_TEXTURE_RESOLUTION = 512;

            RC.SetBlendState(null);
            RC.SetInputLayout(null);

            RC.PixelShader.Set(m_ps);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(1, m_cb);

            MyBorrowedRwTextureManager rwTexManager   = MyManagers.RwTexturesPool;
            MyFileTextureManager       fileTexManager = MyManagers.FileTextures;

            foreach (var texture in texturesToRender)
            {
                ISrvBindable tex = fileTexManager.GetTexture(texture.TextureName, MyFileTextureEnum.COLOR_METAL, true);
                if (tex == null)
                {
                    continue;
                }

                Vector2  texSize = tex.Size;
                Vector2I renderTargetResolution = new Vector2I(RENDER_TEXTURE_RESOLUTION, RENDER_TEXTURE_RESOLUTION);
                if (texSize.Y > 0)
                {
                    if (texSize.Y < RENDER_TEXTURE_RESOLUTION)
                    {
                        renderTargetResolution.X = (int)texSize.X;
                        renderTargetResolution.Y = (int)texSize.Y;
                    }
                    else
                    {
                        renderTargetResolution.X *= (int)(texSize.X / texSize.Y);
                    }
                }

                MyViewport viewport = new MyViewport(renderTargetResolution.X, renderTargetResolution.Y);

                IBorrowedRtvTexture renderTexture = rwTexManager.BorrowRtv("MySaveExportedTextures.RenderColoredTextures",
                                                                           renderTargetResolution.X, renderTargetResolution.Y, SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, 1, 0);

                RC.SetRtv(renderTexture);

                // Set color
                var     mapping = MyMapping.MapDiscard(m_cb);
                Vector4 color   = new Vector4(texture.ColorMaskHSV, 1);
                mapping.WriteAndPosition(ref color);
                mapping.Unmap();

                // Set texture
                RC.PixelShader.SetSrv(0, tex);

                // Draw
                MyScreenPass.DrawFullscreenQuad(viewport);

                // Save to file
                MyTextureData.ToFile(renderTexture, texture.PathToSave, ImageFileFormat.Png);

                renderTexture.Release();
            }

            texturesToRender.Clear();

            RC.SetRtv(null);
            RC.PixelShader.SetSrvs(0, MyGBuffer.Main);
        }
示例#10
0
        public 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();

            int samples = MyRender11.Settings.User.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);

            foreach (var pair in m_highlights)
            {
                MyActor actor = MyIDTracker <MyActor> .FindByID(pair.Key);

                if (actor == null)
                {
                    MyRenderProxy.Fail("The actor cannot be found for highlight. This bug is outside of the renderer.");
                    continue;
                }
                MyRenderableComponent renderableComponent = actor.GetRenderable();
                MyInstanceComponent   instanceComponent   = actor.GetInstance();
                if (renderableComponent != null)
                {
                    DrawRenderableComponent(actor, renderableComponent, pair.Value);
                }
                else if (instanceComponent != null)
                {
                    DrawInstanceComponent(instanceComponent, pair.Value);
                }
                else
                {
                    // If an actor has been removed without removing outlines, just remove the outlines too
                    m_keysToRemove.Add(pair.Key);
                    MyRenderProxy.Fail("The actor has been removed, but the highligh is still active. This bug is caused by the issue out of the renderer.");
                }
            }

            MyHighlightPass.Instance.End();
            RC.SetBlendState(null);
            foreach (var outlineKey in m_keysToRemove)
            {
                m_highlights.Remove(outlineKey);
            }
            m_keysToRemove.Clear();

            ISrvBindable initialSourceView = rgba8_1;
            IRtvBindable renderTargetview  = rgba8_1;

            float maxThickness = 0f;

            foreach (var pair in m_highlights)
            {
                foreach (MyHighlightDesc descriptor in pair.Value)
                {
                    maxThickness = Math.Max(maxThickness, descriptor.Thickness);
                }
            }

            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);
        }
示例#11
0
        internal static IBorrowedRtvTexture Run()
        {
            ProfilerShort.Begin("MyOutline.Run");
            MyGpuProfiler.IC_BeginBlock("MyOutline.Run");
            // set resolved depth/ stencil
            // render all with proper depth-stencil state
            // blur
            // blend to main target testing with stencil again

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

            MyOutlinePass.Instance.PerFrame();
            MyOutlinePass.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("MyOutline.Rgba8_1", Format.R8G8B8A8_UNorm_SRgb, samples);

            RC.ClearRtv(rgba8_1, new SharpDX.Color4(0, 0, 0, 0));
            RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadWrite, rgba8_1);

            float maxThickness = 0f;

            foreach (var pair in m_outlines)
            {
                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 (MyOutlineDesc 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);
                    }
                }
            }

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

            foreach (var outlineKey in m_keysToRemove)
            {
                m_outlines.Remove(outlineKey);
            }

            m_keysToRemove.SetSize(0);

            ISrvBindable initialSourceView = rgba8_1;
            IRtvBindable renderTargetview  = rgba8_1;

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

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

            return(rgba8_1);
        }
示例#12
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;
        }
示例#13
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();
            }

            ProfilerShort.Begin("MyLights.Update");
            MyLights.Update();
            ProfilerShort.End();

            ProfilerShort.Begin("DynamicGeometryRenderer");
            MyCullQuery cullQuery = m_dynamicGeometryRenderer.PrepareCullQuery(true); // it is used to share rendering settings between the old and the new pipeline

            ProfilerShort.End();

            MyGpuProfiler.IC_BeginBlock("NewGeometryRenderer");
            ProfilerShort.Begin("NewGeometryRenderer");
            IGeometrySrvStrategy geometrySrvStrategy = MyManagers.GeometrySrvResolver.GetGeometrySrvStrategy();

            if (MyDebugGeometryStage2.EnableNewGeometryPipeline)
            {
                MyManagers.GeometryRenderer.Render(cullQuery, geometrySrvStrategy);
            }
            ProfilerShort.End();
            MyGpuProfiler.IC_EndBlock();

            MyGpuProfiler.IC_BeginBlock("MyGeometryRenderer.Render");
            Debug.Assert(m_commandLists.Count == 0, "Not all command lists executed last frame!");
            ProfilerShort.Begin("DynamicGeometryRenderer");
            m_dynamicGeometryRenderer.Render(m_commandLists);
            ProfilerShort.End();    // End function block
            if (MyScene.SeparateGeometry)
            {
                ProfilerShort.Begin("StaticGeometryRenderer");
                m_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 = MyManagers.RwTexturesPool.BorrowRtv("MyScreenDependants.AmbientOcclusion",
                                                                                          ResolutionI.X, ResolutionI.Y, SharpDX.DXGI.Format.R8_UNorm);
            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 && Settings.User.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 = MyManagers.RwTexturesPool.BorrowRtv("MyScreenDependants.AmbientOcclusionHelper",
                                                                                                         ResolutionI.X, ResolutionI.Y, SharpDX.DXGI.Format.R8_UNorm);

                        MyBlur.Run(ambientOcclusionRtv, ambientOcclusionHelper, ambientOcclusionRtv, clearColor: Color4.White);
                        ambientOcclusionHelper.Release();
                    }
                    MyGpuProfiler.IC_EndBlockAlways();
                }
                else if (MyHBAO.Params.Enabled && Settings.User.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)
                {
                    MyLightsRendering.Render(postProcessedShadows, ambientOcclusionRtv);
                }
                MyGpuProfiler.IC_EndBlockAlways();
                postProcessedShadows.Release();

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

            ProfilerShort.BeginNextBlock("Occlusion Queries");
            MyGpuProfiler.IC_BeginBlock("Occlusion Queries");
            MyOcclusionQueryRenderer.Render(RC, MyGBuffer.Main.ResolvedDepthStencil, MyGBuffer.Main.LBuffer);
            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("MyHighlight.Run");
            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);
        }
 public static void Select(IBorrowedRtvTexture tex)
 {
     Deselect();
     tex.AddRef();
     m_selBorrowedRtvTexture = tex;
 }
示例#15
0
 public static void Select(IBorrowedRtvTexture tex)
 {
     Deselect();
     tex.AddRef();
     m_selBorrowedRtvTexture = tex;
 }