private static void OnDeviceReset() { MyManagers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyTransparentRendering.OnDeviceReset(); ResetShadows(MyShadowCascades.Settings.NewData.CascadesCount, Settings.User.ShadowQuality.ShadowCascadeResolution()); MyBillboardRenderer.OnDeviceReset(); MyScreenDecals.OnDeviceReset(); MyMeshMaterials1.OnDeviceReset(); MyVoxelMaterials1.OnDeviceReset(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); MyScreenDecals.OnDeviceReset(); }
internal static void OnDeviceReset() { MyHwBuffers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyPipelineStates.OnDeviceReset(); MyTextures.OnDeviceReset(); MyRwTextures.OnDeviceEnd(); MyShadows.OnDeviceReset(); MyBillboardRenderer.OnDeviceRestart(); MyMeshMaterials1.InvalidateMaterials(); MyVoxelMaterials1.InvalidateMaterials(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); }
internal static void OnDeviceReset() { MyHwBuffers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyPipelineStates.OnDeviceReset(); MyTextures.OnDeviceReset(); MyRwTextures.OnDeviceReset(); MyTransparentRendering.OnDeviceReset(); ResetShadows(Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyBillboardRenderer.OnDeviceRestart(); MyScreenDecals.OnDeviceReset(); MyMeshMaterials1.InvalidateMaterials(); MyVoxelMaterials1.InvalidateMaterials(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); MyScreenDecals.OnDeviceReset(); }
internal static unsafe void InitSubsystems() { InitializeBlendStates(); InitializeRasterizerStates(); InitilizeSamplerStates(); MyCommon.Init(); MyPipelineStates.Init(); MyTextures.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyRwTextures.Init(); MyHwBuffers.Init(); MyMeshes.Init(); MyMeshTableSRV.Init(); MyMergeInstancing.Init(); MyGeometryRenderer.Init(); MyLightRendering.Init(); MyShadows.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyFoliageRenderer.Init(); MyOutline.Init(); MyComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyGPUFoliageGenerating.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyShadowsResolve.Init(); MyAtmosphereRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); //MyShaderFactory.RunCompilation(); // rebuild }
internal static unsafe void InitSubsystems() { MyRwTextures.Init(); MyHwBuffers.Init(); MyPipelineStates.Init(); ResetShadows(MyRenderProxy.Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyRender11.Init(); MyCommon.Init(); SamplerStates.Init(); MyDepthStencilState.Init(); MyTextures.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyMeshes.Init(); MyMeshTableSRV.Init(); MyLightRendering.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyOutline.Init(); MyBlur.Init(); MyTransparentRendering.Init(); MyFoliageComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyAtmosphereRenderer.Init(); MyCloudRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyPlanetBlur.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); }
private static void PrepareGameScene() { ProfilerShort.Begin("PrepareGameScene"); ProfilerShort.Begin("Stats"); ResetStats(); ProfilerShort.BeginNextBlock("GBuffer clear"); MyGBuffer.Main.Clear(); ProfilerShort.BeginNextBlock("Constants"); MySceneMaterials.PreFrame(); MyCommon.UpdateFrameConstants(); ProfilerShort.End(); ProfilerShort.End(); }
private static void PrepareGameScene() { ProfilerShort.Begin("PrepareGameScene"); ProfilerShort.Begin("Stats"); ResetStats(); ProfilerShort.BeginNextBlock("GBuffer clear"); MyGBuffer.Main.Clear(VRageMath.Color.Black); //TODO: Find out why clearing to White affects result image //MyGBuffer.Main.Clear(MyEnvironment.BackgroundColor); ProfilerShort.BeginNextBlock("Constants"); MySceneMaterials.PreFrame(); MyCommon.UpdateFrameConstants(); ProfilerShort.End(); ProfilerShort.End(); }
internal static void DispatchCulling() { //MyPerformanceCounter.PerCameraDraw11Write.RenderableObjectsNum = MyRenderablesBoundingTree.m_tree.CountLeaves(MyRenderablesBoundingTree.m_tree.GetRoot()); MyRender11.GetRenderProfiler().StartProfilingBlock("CreateTasksAndWait"); List <Task> tasks = new List <Task>(); for (int i = 1; i < m_cullQuery.Size; i++) { m_cullQuery.FrustumQuery[i].List.Clear(); m_cullQuery.FrustumQuery[i].IsInsideList.Clear(); tasks.Add(Parallel.Start(new MyCullingWork(m_cullQuery.FrustumQuery[i]))); } if (m_cullQuery.Size > 0) { m_cullQuery.FrustumQuery[0].List.Clear(); m_cullQuery.FrustumQuery[0].IsInsideList.Clear(); new MyCullingWork(m_cullQuery.FrustumQuery[0]).DoWork(); } foreach (var task in tasks) { task.Wait(); } MyRender11.GetRenderProfiler().EndProfilingBlock(); //bool ok = false; //for (int i = 0; i < m_cullQuery.Size; i++ ) //{ // if(m_cullQuery.FrustumQuery[i].Type == MyFrustumEnum.MainFrustum) // { // foreach(var e in m_cullQuery.FrustumQuery[i].List) // { // if(e.Proxies[0].Parent.m_owner.ID == 1417) // { // ok = true; break; // } // } // } //} //var x = 7; MyRender11.GetRenderProfiler().StartProfilingBlock("ProcessResults"); for (int i = 0; i < m_cullQuery.Size; i++) { if (m_cullQuery.FrustumQuery[i].Type == MyFrustumEnum.MainFrustum) { MyPerformanceCounter.PerCameraDraw11Write.ViewFrustumObjectsNum = m_cullQuery.FrustumQuery[i].List.Count; int N = m_cullQuery.FrustumQuery[i].List.Count; for (int j = 0; j < N; j++) { foreach (var proxy in m_cullQuery.FrustumQuery[i].List[j].Proxies) { var worldMat = proxy.WorldMatrix; worldMat.Translation -= MyEnvironment.CameraPosition; proxy.ObjectData.LocalMatrix = worldMat; proxy.ObjectData.MaterialIndex = MySceneMaterials.GetDrawMaterialIndex(proxy.PerMaterialIndex); } } } else if (m_cullQuery.FrustumQuery[i].Type == MyFrustumEnum.Cascade0) { MyPerformanceCounter.PerCameraDraw11Write.Cascade0ObjectsNum = m_cullQuery.FrustumQuery[i].List.Count; // m_inCascade0.Clear(); int N = m_cullQuery.FrustumQuery[i].List.Count; for (int j = 0; j < N; j++) { if (m_cullQuery.FrustumQuery[i].IsInsideList[j]) { var item = m_cullQuery.FrustumQuery[i].List[j]; m_inCascade0.Add(item); } } // m_inCascade0_2.Clear(); N = m_cullQuery.FrustumQuery[i].List2.Count; for (int j = 0; j < N; j++) { if (m_cullQuery.FrustumQuery[i].IsInsideList2[j]) { var item = m_cullQuery.FrustumQuery[i].List2[j]; m_inCascade0_2.Add(item); } } } else if (m_cullQuery.FrustumQuery[i].Type == MyFrustumEnum.Cascade1) { // m_inCascade1.Clear(); var list = m_cullQuery.FrustumQuery[i].List; int N = list.Count; for (int j = 0; j < N; j++) { var item = list[j]; if (m_inCascade0.Contains(item)) { // drop list.RemoveAtFast(j); j--; N--; } else if (m_cullQuery.FrustumQuery[i].IsInsideList[j]) { m_inCascade1.Add(item); } } // m_inCascade1_2.Clear(); var list2 = m_cullQuery.FrustumQuery[i].List2; N = list2.Count; for (int j = 0; j < N; j++) { var item = list2[j]; if (m_inCascade0_2.Contains(item)) { // drop list2.RemoveAtFast(j); j--; N--; } else if (m_cullQuery.FrustumQuery[i].IsInsideList2[j]) { m_inCascade1_2.Add(item); } } MyPerformanceCounter.PerCameraDraw11Write.Cascade1ObjectsNum = m_cullQuery.FrustumQuery[i].List.Count; } else if (m_cullQuery.FrustumQuery[i].Type == MyFrustumEnum.Cascade2) { // m_inCascade2.Clear(); var list = m_cullQuery.FrustumQuery[i].List; int N = list.Count; for (int j = 0; j < N; j++) { var item = list[j]; if (m_inCascade0.Contains(item) || m_inCascade1.Contains(item)) { // drop list.RemoveAtFast(j); j--; N--; } else if (m_cullQuery.FrustumQuery[i].IsInsideList[j]) { m_inCascade2.Add(item); } } // m_inCascade2_2.Clear(); var list2 = m_cullQuery.FrustumQuery[i].List2; N = list2.Count; for (int j = 0; j < N; j++) { var item = list2[j]; if (m_inCascade0_2.Contains(item) || m_inCascade1_2.Contains(item)) { // drop list2.RemoveAtFast(j); j--; N--; } else if (m_cullQuery.FrustumQuery[i].IsInsideList2[j]) { m_inCascade2_2.Add(item); } } MyPerformanceCounter.PerCameraDraw11Write.Cascade2ObjectsNum = m_cullQuery.FrustumQuery[i].List.Count; } else if (m_cullQuery.FrustumQuery[i].Type == MyFrustumEnum.Cascade3) { var list = m_cullQuery.FrustumQuery[i].List; int N = list.Count; for (int j = 0; j < N; j++) { var item = list[j]; if (m_inCascade0.Contains(item) || m_inCascade1.Contains(item) || m_inCascade2.Contains(item)) { // drop list.RemoveAtFast(j); j--; N--; } } // var list2 = m_cullQuery.FrustumQuery[i].List2; N = list2.Count; for (int j = 0; j < N; j++) { var item = list2[j]; if (m_inCascade0_2.Contains(item) || m_inCascade1_2.Contains(item) || m_inCascade2_2.Contains(item)) { // drop list2.RemoveAtFast(j); j--; N--; } } MyPerformanceCounter.PerCameraDraw11Write.Cascade3ObjectsNum = m_cullQuery.FrustumQuery[i].List.Count; } if (m_cullQuery.FrustumQuery[i].Ignored != null) { var list = m_cullQuery.FrustumQuery[i].List; int N = list.Count; for (int j = 0; j < N; j++) { if (list[j].Proxies.Length > 0 && m_cullQuery.FrustumQuery[i].Ignored.Contains(list[j].Proxies[0].Parent.m_owner.ID)) { list.RemoveAtFast(j); j--; N--; } } } } MyRender11.GetRenderProfiler().EndProfilingBlock(); }
internal static unsafe void InitSubsystems() { MyManagers.OnDeviceInit(); //MyRwTextures.Init(); MyHwBuffers.Init(); ResetShadows(MyShadowCascades.Settings.NewData.CascadesCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyRender11.Init(); MyCommon.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyMeshes.Init(); MyMeshTableSrv.Init(); MyLightRendering.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyOutline.Init(); MyBlur.Init(); MyTransparentRendering.Init(); MyFoliageComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyAtmosphereRenderer.Init(); MyCloudRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); MyHBAO.Init(); try { if (m_settings.UseStereoRendering) { var openVR = new MyOpenVR(); MyStereoStencilMask.InitUsingOpenVR(); } } catch (System.Exception e) { if (!VRage.MyCompilationSymbols.DX11ForceStereo) { throw; } MyStereoStencilMask.InitUsingUndefinedMask(); } }
internal static void PrepareFrame() { MyGBuffer.Main.Clear(); MySceneMaterials.PreFrame(); }
private static void DrawGameScene(bool blitToBackbuffer) { ResetStats(); MyCommon.UpdateFrameConstants(); // todo: shouldn't be necessary if (true) { MyImmediateRC.RC.Clear(); MyImmediateRC.RC.Context.ClearState(); } MyRender11.GetRenderProfiler().StartProfilingBlock("MyGeometryRenderer.Render"); MyGpuProfiler.IC_BeginBlock("MyGeometryRenderer.Render"); MyGeometryRenderer.Render(); MyGpuProfiler.IC_EndBlock(); MyRender11.GetRenderProfiler().EndProfilingBlock(); // cleanup context atfer deferred lists if (MyRender11.DeferredContextsEnabled) { MyImmediateRC.RC.Clear(); } // todo: shouldn't be necessary if (true) { MyImmediateRC.RC.Clear(); MyImmediateRC.RC.Context.ClearState(); } MyRender11.GetRenderProfiler().StartProfilingBlock("Render decals"); MyGpuProfiler.IC_BeginBlock("Render decals"); MyRender11.CopyGbufferToScratch(); MyScreenDecals.Draw(); MyGpuProfiler.IC_EndBlock(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MyRender11.GetRenderProfiler().StartProfilingBlock("Render foliage"); MyGpuProfiler.IC_BeginBlock("Render foliage"); MyFoliageRenderer.Render(); MyGpuProfiler.IC_EndBlock(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MySceneMaterials.MoveToGPU(); MyRender11.GetRenderProfiler().StartProfilingBlock("Postprocessing"); MyGpuProfiler.IC_BeginBlock("Postprocessing"); if (MultisamplingEnabled) { MyRender11.Context.ClearDepthStencilView(MyScreenDependants.m_resolvedDepth.m_DSV, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0); MyGpuProfiler.IC_BeginBlock("MarkAAEdges"); MyAAEdgeMarking.Run(); MyGpuProfiler.IC_EndBlock(); MyDepthResolve.Run(MyScreenDependants.m_resolvedDepth, MyGBuffer.Main.DepthStencil.Depth); } MyGpuProfiler.IC_BeginBlock("MarkCascades"); MyShadows.MarkCascadesInStencil(); MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Shadows resolve"); MyShadowsResolve.Run(); MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("SSAO"); if (Postprocess.EnableSsao) { MySSAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.Depth : MyGBuffer.Main.DepthStencil.Depth); } else { MyRender11.Context.ClearRenderTargetView(MyScreenDependants.m_ambientOcclusion.m_RTV, Color4.White); } MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Lights"); MyLightRendering.Render(); MyGpuProfiler.IC_EndBlock(); MyRender11.GetRenderProfiler().StartProfilingBlock("Billboards"); MyGpuProfiler.IC_BeginBlock("Billboards"); MyRender11.Context.ClearRenderTargetView((MyScreenDependants.m_particlesRT as IRenderTargetBindable).RTV, new Color4(0, 0, 0, 0)); if (MyRender11.MultisamplingEnabled) { MyBillboardRenderer.Render(MyScreenDependants.m_particlesRT, MyScreenDependants.m_resolvedDepth, MyScreenDependants.m_resolvedDepth.Depth); } else { MyBillboardRenderer.Render(MyScreenDependants.m_particlesRT, MyGBuffer.Main.DepthStencil, MyGBuffer.Main.DepthStencil.Depth); } MyBlendTargets.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), MyScreenDependants.m_particlesRT, MyRender11.BlendAlphaPremult); MyGpuProfiler.IC_EndBlock(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MyAtmosphereRenderer.Render(); MyGpuProfiler.IC_BeginBlock("Luminance reduction"); MyBindableResource avgLum = null; if (MyRender11.MultisamplingEnabled) { //MyLBufferResolve.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBufferResolved), MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), MyGBuffer.Main.DepthStencil.Stencil); MyImmediateRC.RC.Context.ResolveSubresource(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer).m_resource, 0, MyGBuffer.Main.Get(MyGbufferSlot.LBufferResolved).m_resource, 0, SharpDX.DXGI.Format.R11G11B10_Float); } if (m_resetEyeAdaptation) { MyImmediateRC.RC.Context.ClearUnorderedAccessView(m_prevLum.m_UAV, Int4.Zero); m_resetEyeAdaptation = false; } avgLum = MyLuminanceAverage.Run(m_reduce0, m_reduce1, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), m_prevLum, m_localLum); MyGpuProfiler.IC_EndBlock(); if (MyRender11.Settings.DispalyHdrDebug) { var src = MyGBuffer.Main.Get(MyGbufferSlot.LBuffer) as MyRenderTarget; MyHdrDebugTools.CreateHistogram(src.m_SRV, src.m_resolution, src.m_samples.X); } MyGpuProfiler.IC_BeginBlock("Bloom"); var bloom = MyBloom.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), avgLum); MyGpuProfiler.IC_EndBlock(); MyBindableResource tonemapped; if (MyRender11.FxaaEnabled) { tonemapped = m_rgba8_linear; } else { tonemapped = m_uav3; } MyGpuProfiler.IC_BeginBlock("Tone mapping"); MyToneMapping.Run(tonemapped, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), avgLum, bloom, MyRender11.Settings.EnableTonemapping && Postprocess.EnableTonemapping && MyRender11.RenderSettings.TonemappingEnabled); MyGpuProfiler.IC_EndBlock(); MyBindableResource renderedImage; if (MyRender11.FxaaEnabled) { MyGpuProfiler.IC_BeginBlock("FXAA"); MyFXAA.Run(m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView }), tonemapped); MyGpuProfiler.IC_EndBlock(); renderedImage = m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView }); } else { //renderedImage = (tonemapped as MyCustomTexture).GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView }); renderedImage = tonemapped; } if (MyOutline.AnyOutline()) { MyOutline.Run(); if (MyRender11.FxaaEnabled) { MyBlendTargets.RunWithStencil(m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView }), MyRender11.m_rgba8_1, MyRender11.BlendAdditive); } else { if (MyRender11.MultisamplingEnabled) { MyBlendTargets.RunWithPixelStencilTest(tonemapped, MyRender11.m_rgba8_1, MyRender11.BlendAdditive); } else { MyBlendTargets.RunWithStencil(tonemapped, MyRender11.m_rgba8_1, MyRender11.BlendAdditive); } } } m_finalImage = renderedImage; if (blitToBackbuffer) { MyCopyToRT.Run(Backbuffer, renderedImage); } if (MyRender11.Settings.DispalyHdrDebug) { MyHdrDebugTools.DisplayHistogram(Backbuffer.m_RTV, (avgLum as IShaderResourceBindable).SRV); } MyGpuProfiler.IC_EndBlock(); MyRender11.GetRenderProfiler().EndProfilingBlock(); }
// 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); }
internal static void ProcessFrustumCullingResults() { if (m_indicesToRemove == null) { m_indicesToRemove = new List <int>(); } foreach (MyFrustumCullQuery frustumQuery in m_cullQuery.FrustumQueries) { var cullProxies = frustumQuery.List; bool isShadowFrustum = ((frustumQuery.Type == MyFrustumEnum.ShadowCascade) || (frustumQuery.Type == MyFrustumEnum.ShadowProjection)); for (int cullProxyIndex = 0; cullProxyIndex < cullProxies.Count; ++cullProxyIndex) { MyCullProxy cullProxy = cullProxies[cullProxyIndex]; if (cullProxy == null) { continue; } foreach (MyRenderableProxy proxy in cullProxy.Proxies) { bool shouldCastShadows = (proxy.Flags & MyRenderableProxyFlags.CastShadows) == MyRenderableProxyFlags.CastShadows; if (!proxy.IsInViewDistance() || (isShadowFrustum && !shouldCastShadows)) { m_indicesToRemove.Add(cullProxyIndex); break; } var worldMat = proxy.WorldMatrix; worldMat.Translation -= MyEnvironment.CameraPosition; proxy.ObjectData.LocalMatrix = worldMat; proxy.ObjectData.MaterialIndex = MySceneMaterials.GetDrawMaterialIndex(proxy.PerMaterialIndex); } } for (int removeIndex = m_indicesToRemove.Count - 1; removeIndex >= 0; --removeIndex) { cullProxies.RemoveAtFast(m_indicesToRemove[removeIndex]); frustumQuery.IsInsideList.RemoveAtFast(m_indicesToRemove[removeIndex]); } m_indicesToRemove.Clear(); if (frustumQuery.Type == MyFrustumEnum.MainFrustum) { MyPerformanceCounter.PerCameraDraw11Write.ViewFrustumObjectsNum = frustumQuery.List.Count; } else if (frustumQuery.Type == MyFrustumEnum.ShadowCascade) { while (m_shadowCascadeProxies.Count < MyRenderProxy.Settings.ShadowCascadeCount) { m_shadowCascadeProxies.Add(new HashSet <MyCullProxy>()); } while (m_shadowCascadeProxies_2.Count < MyRenderProxy.Settings.ShadowCascadeCount) { m_shadowCascadeProxies_2.Add(new HashSet <MyCullProxy_2>()); } // List 1 m_shadowCascadeProxies[frustumQuery.CascadeIndex].Clear(); for (int cullProxyIndex = 0; cullProxyIndex < cullProxies.Count; ++cullProxyIndex) { var cullProxy = cullProxies[cullProxyIndex]; bool containedInHigherCascade = false; // Cull items if they're fully contained in higher resolution cascades for (int hashSetIndex = 0; hashSetIndex < frustumQuery.CascadeIndex; ++hashSetIndex) { if (m_shadowCascadeProxies[hashSetIndex].Contains(cullProxy)) { cullProxies.RemoveAtFast(cullProxyIndex); frustumQuery.IsInsideList.RemoveAtFast(cullProxyIndex); --cullProxyIndex; containedInHigherCascade = true; break; } } if (!containedInHigherCascade && frustumQuery.IsInsideList[cullProxyIndex]) { m_shadowCascadeProxies[frustumQuery.CascadeIndex].Add(cullProxy); } } // List 2 var cullProxies_2 = frustumQuery.List2; m_shadowCascadeProxies_2[frustumQuery.CascadeIndex].Clear(); for (int cullProxyIndex = 0; cullProxyIndex < cullProxies_2.Count; ++cullProxyIndex) { var cullProxy_2 = cullProxies_2[cullProxyIndex]; bool containedInHigherCascade = false; // Cull items if they're fully contained in higher resolution cascades for (int hashSetIndex = 0; hashSetIndex < frustumQuery.CascadeIndex; ++hashSetIndex) { if (m_shadowCascadeProxies_2[hashSetIndex].Contains(cullProxy_2)) { cullProxies_2.RemoveAtFast(cullProxyIndex); frustumQuery.IsInsideList2.RemoveAtFast(cullProxyIndex); --cullProxyIndex; containedInHigherCascade = true; break; } } if (!containedInHigherCascade && frustumQuery.IsInsideList2[cullProxyIndex]) { m_shadowCascadeProxies_2[frustumQuery.CascadeIndex].Add(cullProxy_2); } } MyPerformanceCounter.PerCameraDraw11Write.ShadowCascadeObjectsNum[frustumQuery.CascadeIndex] = frustumQuery.List.Count; } if (frustumQuery.Ignored != null) { for (int cullProxyIndex = 0; cullProxyIndex < cullProxies.Count; cullProxyIndex++) { if (cullProxies[cullProxyIndex].Proxies.Length > 0 && frustumQuery.Ignored.Contains(cullProxies[cullProxyIndex].Proxies[0].Parent.m_owner.ID)) { cullProxies.RemoveAtFast(cullProxyIndex); --cullProxyIndex; } } } } }
// Returns the final image and copies it to renderTarget if non-null private static MyBindableResource DrawGameScene(MyBindableResource renderTarget) { ProfilerShort.Begin("DrawGameScene"); PrepareGameScene(); // todo: shouldn't be necessary if (true) { ProfilerShort.Begin("Clear"); MyRenderContext.Immediate.Clear(); MyRenderContext.Immediate.DeviceContext.ClearState(); ProfilerShort.End(); } Debug.Assert(m_commandLists.Count == 0, "Not all command lists executed last frame!"); DynamicGeometryRenderer.Render(m_commandLists, true); if (MyScene.SeparateGeometry) { StaticGeometryRenderer.Render(m_commandLists, false); } SendGlobalOutputMessages(); ExecuteCommandLists(m_commandLists); MyEnvironmentProbe.FinalizeEnvProbes(); // cleanup context atfer deferred lists if (MyRender11.DeferredContextsEnabled) { ProfilerShort.Begin("Clear2"); MyRenderContext.Immediate.Clear(); ProfilerShort.End(); } // todo: shouldn't be necessary if (true) { ProfilerShort.Begin("Clear3"); MyRenderContext.Immediate.Clear(); MyRenderContext.Immediate.DeviceContext.ClearState(); ProfilerShort.End(); } ProfilerShort.Begin("Render decals"); MyGpuProfiler.IC_BeginBlock("Render decals"); MyRender11.CopyGbufferToScratch(); MyScreenDecals.Draw(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("Render foliage"); MyGpuProfiler.IC_BeginBlock("Render foliage"); m_foliageRenderer.Render(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("MySceneMaterials.MoveToGPU"); MySceneMaterials.MoveToGPU(); ProfilerShort.BeginNextBlock("Postprocessing"); MyGpuProfiler.IC_BeginBlock("Postprocessing"); if (MultisamplingEnabled) { MyRender11.DeviceContext.ClearDepthStencilView(MyScreenDependants.m_resolvedDepth.m_DSV, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0); MyGpuProfiler.IC_BeginBlock("MarkAAEdges"); MyAAEdgeMarking.Run(); MyGpuProfiler.IC_EndBlock(); MyDepthResolve.Run(MyScreenDependants.m_resolvedDepth, MyGBuffer.Main.DepthStencil.Depth); } if (MyScene.SeparateGeometry) { MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades); DynamicShadows.ShadowCascades.PostProcess(MyRender11.PostProcessedShadows, MyShadowCascades.CombineShadowmapArray); } else { DynamicShadows.ShadowCascades.PostProcess(MyRender11.PostProcessedShadows, DynamicShadows.ShadowCascades.CascadeShadowmapArray); } MyGpuProfiler.IC_BeginBlock("SSAO"); if (Postprocess.EnableSsao) { MySSAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.Depth : MyGBuffer.Main.DepthStencil.Depth); if (MySSAO.UseBlur) { MyBlur.Run(MyScreenDependants.m_ambientOcclusion, MyScreenDependants.m_ambientOcclusionHelper, MyScreenDependants.m_ambientOcclusion); } } else { MyRender11.DeviceContext.ClearRenderTargetView(MyScreenDependants.m_ambientOcclusion.m_RTV, Color4.White); } MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Lights"); MyLightRendering.Render(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("Billboards"); MyGpuProfiler.IC_BeginBlock("Billboards"); if (MyRender11.MultisamplingEnabled) { MyBillboardRenderer.Render(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), MyScreenDependants.m_resolvedDepth, MyScreenDependants.m_resolvedDepth.Depth); } else { MyBillboardRenderer.Render(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), MyGBuffer.Main.DepthStencil, MyGBuffer.Main.DepthStencil.Depth); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("Atmosphere"); MyGpuProfiler.IC_BeginBlock("Atmosphere"); MyAtmosphereRenderer.Render(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("Clouds"); MyGpuProfiler.IC_BeginBlock("Clouds"); MyCloudRenderer.Render(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); MyGpuProfiler.IC_BeginBlock("Luminance reduction"); MyBindableResource avgLum = null; if (MyRender11.MultisamplingEnabled) { MyRenderContext.Immediate.DeviceContext.ResolveSubresource(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer).m_resource, 0, MyGBuffer.Main.Get(MyGbufferSlot.LBufferResolved).m_resource, 0, SharpDX.DXGI.Format.R11G11B10_Float); } if (m_resetEyeAdaptation) { MyRenderContext.Immediate.DeviceContext.ClearUnorderedAccessView(m_prevLum.m_UAV, Int4.Zero); m_resetEyeAdaptation = false; } avgLum = MyLuminanceAverage.Run(m_reduce0, m_reduce1, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), m_prevLum); MyGpuProfiler.IC_EndBlock(); if (MyRender11.Settings.DisplayHdrDebug) { var src = MyGBuffer.Main.Get(MyGbufferSlot.LBuffer) as MyRenderTarget; MyHdrDebugTools.CreateHistogram(src.m_SRV, src.m_resolution, src.m_samples.X); } MyGpuProfiler.IC_BeginBlock("Bloom"); var bloom = MyBloom.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), avgLum); MyGpuProfiler.IC_EndBlock(); MyBindableResource tonemapped; if (MyRender11.FxaaEnabled) { tonemapped = m_rgba8_linear; } else { tonemapped = m_uav3; } MyGpuProfiler.IC_BeginBlock("Tone mapping"); MyToneMapping.Run(tonemapped, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), avgLum, bloom, Postprocess.EnableTonemapping); MyGpuProfiler.IC_EndBlock(); MyBindableResource renderedImage; if (MyRender11.FxaaEnabled) { MyGpuProfiler.IC_BeginBlock("FXAA"); MyFXAA.Run(m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView }), tonemapped); MyGpuProfiler.IC_EndBlock(); renderedImage = m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView }); } else { //renderedImage = (tonemapped as MyCustomTexture).GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView }); renderedImage = tonemapped; } ProfilerShort.Begin("Outline"); if (MyOutline.AnyOutline()) { MyOutline.Run(); MyGpuProfiler.IC_BeginBlock("Outline Blending"); ProfilerShort.Begin("Outline Blending"); if (MyRender11.FxaaEnabled) { MyBlendTargets.RunWithStencil( m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView }), MyRender11.m_rgba8_1, MyRender11.BlendAdditive, MyDepthStencilState.TestOutlineMeshStencil, 0x40); MyBlendTargets.RunWithStencil( m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView }), MyRender11.m_rgba8_1, MyRender11.BlendTransparent, MyDepthStencilState.TestHighlightMeshStencil, 0x40); } else { if (MyRender11.MultisamplingEnabled) { MyBlendTargets.RunWithPixelStencilTest(tonemapped, MyRender11.m_rgba8_ms, MyRender11.BlendAdditive); MyBlendTargets.RunWithPixelStencilTest(tonemapped, MyRender11.m_rgba8_ms, MyRender11.BlendTransparent, true); } else { MyBlendTargets.RunWithStencil(tonemapped, MyRender11.m_rgba8_1, MyRender11.BlendAdditive, MyDepthStencilState.TestOutlineMeshStencil, 0x40); MyBlendTargets.RunWithStencil(tonemapped, MyRender11.m_rgba8_1, MyRender11.BlendTransparent, MyDepthStencilState.TestHighlightMeshStencil, 0x40); } } ProfilerShort.End(); MyGpuProfiler.IC_EndBlock(); } ProfilerShort.End(); if (renderTarget != null) { MyCopyToRT.Run(renderTarget, renderedImage); } if (MyRender11.Settings.DisplayHdrDebug) { MyHdrDebugTools.DisplayHistogram((renderTarget as IRenderTargetBindable).RTV, (avgLum as IShaderResourceBindable).SRV); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); return(renderedImage); }
// Returns the final image and copies it to renderTarget if non-null private static MyBindableResource DrawGameScene(MyBindableResource renderTarget) { MyGpuProfiler.IC_BeginBlock("Clear & Geometry Render"); PrepareGameScene(); // todo: shouldn't be necessary if (true) { ProfilerShort.Begin("Clear"); MyRenderContext.Immediate.Clear(); MyRenderContext.Immediate.DeviceContext.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 MyEnvironmentProbe.FinalizeEnvProbes(); #endif // cleanup context atfer deferred lists if (MyRender11.DeferredContextsEnabled) { ProfilerShort.Begin("Clear2"); MyRenderContext.Immediate.Clear(); ProfilerShort.End(); } // todo: shouldn't be necessary if (true) { ProfilerShort.Begin("Clear3"); MyRenderContext.Immediate.Clear(); MyRenderContext.Immediate.DeviceContext.ClearState(); ProfilerShort.End(); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.Begin("Render decals - Opaque"); MyGpuProfiler.IC_BeginBlock("Render decals - Opaque"); MyRender11.CopyGbufferToScratch(); 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(); 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.DeviceContext.ClearDepthStencilView(MyScreenDependants.m_resolvedDepth.m_DSV, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0); MyGpuProfiler.IC_BeginBlock("MarkAAEdges"); MyAAEdgeMarking.Run(); MyGpuProfiler.IC_EndBlock(); MyDepthResolve.Run(MyScreenDependants.m_resolvedDepth, MyGBuffer.Main.DepthStencil.Depth); } ProfilerShort.BeginNextBlock("Shadows"); MyGpuProfiler.IC_BeginBlock("Shadows"); if (MyScene.SeparateGeometry) { MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades); DynamicShadows.ShadowCascades.PostProcess(MyRender11.PostProcessedShadows, MyShadowCascades.CombineShadowmapArray); } else { DynamicShadows.ShadowCascades.PostProcess(MyRender11.PostProcessedShadows, DynamicShadows.ShadowCascades.CascadeShadowmapArray); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("SSAO"); MyGpuProfiler.IC_BeginBlock("SSAO"); if (Postprocess.EnableSsao && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO) { MySSAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.Depth : MyGBuffer.Main.DepthStencil.Depth); if (MySSAO.UseBlur) { MyBlur.Run(MyScreenDependants.m_ambientOcclusion, MyScreenDependants.m_ambientOcclusionHelper, MyScreenDependants.m_ambientOcclusion); } } else { MyRender11.DeviceContext.ClearRenderTargetView(MyScreenDependants.m_ambientOcclusion.m_RTV, Color4.White); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("Lights"); MyGpuProfiler.IC_BeginBlock("Lights"); if (m_debugOverrides.Lighting) { MyLightRendering.Render(); } MyGpuProfiler.IC_EndBlock(); 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(m_transparencyAccum, m_transparencyCoverage); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("PostProcess"); MyGpuProfiler.IC_BeginBlock("PostProcess"); MyGpuProfiler.IC_BeginBlock("Luminance reduction"); MyBindableResource avgLum = null; if (m_resetEyeAdaptation) { MyRenderContext.Immediate.DeviceContext.ClearUnorderedAccessView(m_prevLum.m_UAV, Int4.Zero); m_resetEyeAdaptation = false; } avgLum = MyLuminanceAverage.Run(m_reduce0, m_reduce1, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), m_prevLum); MyGpuProfiler.IC_EndBlock(); if (MyRender11.Settings.DisplayHdrDebug) { var src = MyGBuffer.Main.Get(MyGbufferSlot.LBuffer) as MyRenderTarget; MyHdrDebugTools.CreateHistogram(src.m_SRV, src.m_resolution, src.m_samples.X); } MyGpuProfiler.IC_BeginBlock("Bloom"); MyBindableResource bloom; if (m_debugOverrides.Postprocessing && m_debugOverrides.Bloom) { bloom = MyBloom.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), avgLum); } else { MyRender11.DeviceContext.ClearRenderTargetView(MyRender11.EighthScreenUavHDR.m_RTV, Color4.Black); bloom = MyRender11.EighthScreenUavHDR; } MyGpuProfiler.IC_EndBlock(); MyBindableResource tonemapped; bool fxaa = MyRender11.FxaaEnabled; if (fxaa) { tonemapped = m_rgba8_linear; } else { tonemapped = m_uav3; } MyGpuProfiler.IC_BeginBlock("Tone mapping"); if (m_debugOverrides.Postprocessing && m_debugOverrides.Tonemapping) { MyToneMapping.Run(tonemapped, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), avgLum, bloom, Postprocess.EnableTonemapping); } else { tonemapped = MyGBuffer.Main.Get(MyGbufferSlot.LBuffer); //MyRender11.DeviceContext.CopyResource(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer).m_resource, tonemapped.m_resource); } MyGpuProfiler.IC_EndBlock(); MyBindableResource renderedImage; if (fxaa) { MyGpuProfiler.IC_BeginBlock("FXAA"); MyFXAA.Run(m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView }), tonemapped); MyGpuProfiler.IC_EndBlock(); renderedImage = m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView }); } else { //renderedImage = (tonemapped as MyCustomTexture).GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView }); renderedImage = tonemapped; } ProfilerShort.Begin("Outline"); if (MyOutline.AnyOutline()) { MyOutline.Run(); MyGpuProfiler.IC_BeginBlock("Outline Blending"); ProfilerShort.Begin("Outline Blending"); if (fxaa) { MyBlendTargets.RunWithStencil( m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView }), MyRender11.m_rgba8_1, MyRender11.BlendAdditive, MyDepthStencilState.TestOutlineMeshStencil, 0x40); MyBlendTargets.RunWithStencil( m_rgba8_0.GetView(new MyViewKey { Fmt = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView }), MyRender11.m_rgba8_1, MyRender11.BlendTransparent, MyDepthStencilState.TestHighlightMeshStencil, 0x40); } else { if (MyRender11.MultisamplingEnabled) { MyBlendTargets.RunWithPixelStencilTest(tonemapped, MyRender11.m_rgba8_ms, MyRender11.BlendAdditive); MyBlendTargets.RunWithPixelStencilTest(tonemapped, MyRender11.m_rgba8_ms, MyRender11.BlendTransparent, true); } else { MyBlendTargets.RunWithStencil(tonemapped, MyRender11.m_rgba8_1, MyRender11.BlendAdditive, MyDepthStencilState.TestOutlineMeshStencil, 0x40); MyBlendTargets.RunWithStencil(tonemapped, MyRender11.m_rgba8_1, MyRender11.BlendTransparent, MyDepthStencilState.TestHighlightMeshStencil, 0x40); } } ProfilerShort.End(); MyGpuProfiler.IC_EndBlock(); } ProfilerShort.End(); if (renderTarget != null) { MyCopyToRT.Run(renderTarget, renderedImage); } if (MyRender11.Settings.DisplayHdrDebug) { var target = renderTarget as IRenderTargetBindable; var lum = avgLum as IShaderResourceBindable; if (target != null && lum != null) { MyHdrDebugTools.DisplayHistogram(target.RTV, lum.SRV); } } MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); return(renderedImage); }
protected override void ProcessCullQueryResults(MyCullQuery cullQuery) { ProfilerShort.Begin("Reset"); foreach (MyFrustumCullQuery frustumQuery in cullQuery.FrustumCullQueries) { var cullProxies = frustumQuery.List; foreach (MyCullProxy cullProxy in cullProxies) { cullProxy.Updated = false; cullProxy.FirstFullyContainingCascadeIndex = uint.MaxValue; } } ProfilerShort.End(); foreach (var frustumQuery in cullQuery.FrustumCullQueries) { ProfilerShort.Begin("Distance cull and update"); var cullProxies = frustumQuery.List; bool isShadowFrustum = (frustumQuery.Type == MyFrustumEnum.ShadowCascade) || (frustumQuery.Type == MyFrustumEnum.ShadowProjection); for (int cullProxyIndex = 0; cullProxyIndex < cullProxies.Count; ++cullProxyIndex) { MyCullProxy cullProxy = cullProxies[cullProxyIndex]; if (cullProxy == null || cullProxy.RenderableProxies == null || cullProxy.RenderableProxies.Length == 0 || cullProxy.RenderableProxies[0].Parent == null || !cullProxy.RenderableProxies[0].Parent.IsVisible) { m_tmpIndicesToRemove.Add(cullProxyIndex); continue; } if (!cullProxy.Updated) { var renderableComponent = cullProxy.Parent; if (renderableComponent != null) { renderableComponent.OnFrameUpdate(); if (renderableComponent.IsCulled) { m_tmpIndicesToRemove.Add(cullProxyIndex); continue; } renderableComponent.UpdateInstanceLods(); } // Proxies can get removed in UpdateInstanceLods if (cullProxy.RenderableProxies == null) { m_tmpIndicesToRemove.Add(cullProxyIndex); continue; } foreach (MyRenderableProxy proxy in cullProxy.RenderableProxies) { bool shouldCastShadows = proxy.Flags.HasFlags(MyRenderableProxyFlags.CastShadows) && (proxy.Flags.HasFlags(MyRenderableProxyFlags.DrawOutsideViewDistance) || frustumQuery.CascadeIndex < 4); if (isShadowFrustum && !shouldCastShadows) { m_tmpIndicesToRemove.Add(cullProxyIndex); break; } var worldMat = proxy.WorldMatrix; worldMat.Translation -= MyEnvironment.CameraPosition; proxy.CommonObjectData.LocalMatrix = worldMat; proxy.CommonObjectData.MaterialIndex = MySceneMaterials.GetDrawMaterialIndex(proxy.PerMaterialIndex); } cullProxy.Updated = true; } } for (int removeIndex = m_tmpIndicesToRemove.Count - 1; removeIndex >= 0; --removeIndex) { cullProxies.RemoveAtFast(m_tmpIndicesToRemove[removeIndex]); frustumQuery.IsInsideList.RemoveAtFast(m_tmpIndicesToRemove[removeIndex]); } m_tmpIndicesToRemove.SetSize(0); ProfilerShort.BeginNextBlock("Culling by query type"); if (frustumQuery.Type == MyFrustumEnum.MainFrustum) { MyPerformanceCounter.PerCameraDraw11Write.ViewFrustumObjectsNum = frustumQuery.List.Count; } else if (frustumQuery.Type == MyFrustumEnum.ShadowCascade) { while (m_shadowCascadeProxies2.Count < MyRenderProxy.Settings.ShadowCascadeCount) { m_shadowCascadeProxies2.Add(new HashSet <MyCullProxy_2>()); } bool isHighCascade = frustumQuery.CascadeIndex < 3; if (cullProxies.Count == 0) { MyShadowCascades.ShadowCascadeObjectsCounter[frustumQuery.CascadeIndex] = 0; MyShadowCascades.ShadowCascadeTriangleCounter[frustumQuery.CascadeIndex] = 0; } // List 1 for (int cullProxyIndex = 0; cullProxyIndex < cullProxies.Count; ++cullProxyIndex) { var cullProxy = cullProxies[cullProxyIndex]; if ((isHighCascade && (cullProxy.FirstFullyContainingCascadeIndex < frustumQuery.CascadeIndex - 1)) || (!isHighCascade && cullProxy.FirstFullyContainingCascadeIndex < frustumQuery.CascadeIndex) || cullProxy.RenderableProxies == null) { cullProxies.RemoveAtFast(cullProxyIndex); frustumQuery.IsInsideList.RemoveAtFast(cullProxyIndex); --cullProxyIndex; continue; } else { foreach (var renderableProxy in cullProxy.RenderableProxies) { MyShadowCascades.ShadowCascadeTriangleCounter[frustumQuery.CascadeIndex] += (renderableProxy.InstanceCount > 0 ? renderableProxy.InstanceCount : 1) * renderableProxy.DrawSubmesh.IndexCount / 3; } if (frustumQuery.IsInsideList[cullProxyIndex]) { cullProxy.FirstFullyContainingCascadeIndex = (uint)frustumQuery.CascadeIndex; } } } // List 2 var cullProxies2 = frustumQuery.List2; m_shadowCascadeProxies2[frustumQuery.CascadeIndex].Clear(); for (int cullProxyIndex = 0; cullProxyIndex < cullProxies2.Count; ++cullProxyIndex) { var cullProxy2 = cullProxies2[cullProxyIndex]; bool containedInHigherCascade = false; // Cull items if they're fully contained in higher resolution cascades for (int hashSetIndex = 0; hashSetIndex < frustumQuery.CascadeIndex; ++hashSetIndex) { if (m_shadowCascadeProxies2[hashSetIndex].Contains(cullProxy2)) { cullProxies2.RemoveAtFast(cullProxyIndex); frustumQuery.IsInsideList2.RemoveAtFast(cullProxyIndex); --cullProxyIndex; containedInHigherCascade = true; break; } } if (!containedInHigherCascade && frustumQuery.IsInsideList2[cullProxyIndex]) { m_shadowCascadeProxies2[frustumQuery.CascadeIndex].Add(cullProxy2); } } MyShadowCascades.ShadowCascadeObjectsCounter[frustumQuery.CascadeIndex] = cullProxies.Count; } else if (frustumQuery.Type == MyFrustumEnum.ShadowProjection) { MyShadows.OtherShadowsTriangleCounter = 0; for (int cullProxyIndex = 0; cullProxyIndex < cullProxies.Count; ++cullProxyIndex) { var cullProxy = frustumQuery.List[cullProxyIndex]; if (cullProxy.RenderableProxies == null) { cullProxies.RemoveAtFast(cullProxyIndex); frustumQuery.IsInsideList.RemoveAtFast(cullProxyIndex); --cullProxyIndex; continue; } foreach (var proxy in cullProxy.RenderableProxies) { MyShadows.OtherShadowsTriangleCounter += Math.Max(proxy.InstanceCount, 1) * proxy.DrawSubmesh.IndexCount / 3; } } } ProfilerShort.End(); if (frustumQuery.Ignored != null) { for (int cullProxyIndex = 0; cullProxyIndex < cullProxies.Count; cullProxyIndex++) { if ((cullProxies[cullProxyIndex].RenderableProxies == null || cullProxies[cullProxyIndex].RenderableProxies.Length == 0 || cullProxies[cullProxyIndex].RenderableProxies[0] == null) || (frustumQuery.Ignored.Contains(cullProxies[cullProxyIndex].RenderableProxies[0].Parent.Owner.ID))) { cullProxies.RemoveAtFast(cullProxyIndex); frustumQuery.IsInsideList.RemoveAtFast(cullProxyIndex); --cullProxyIndex; continue; } } } } for (int cascadeIndex = 0; cascadeIndex < MyRenderProxy.Settings.ShadowCascadeCount; ++cascadeIndex) { if (MyShadowCascades.ShadowCascadeObjectsCounter[cascadeIndex] >= 0) { MyPerformanceCounter.PerCameraDraw11Write.ShadowCascadeObjectsNum[cascadeIndex] = MyShadowCascades.ShadowCascadeObjectsCounter[cascadeIndex]; MyShadowCascades.ShadowCascadeObjectsCounter[cascadeIndex] = -1; } if (MyShadowCascades.ShadowCascadeTriangleCounter[cascadeIndex] >= 0) { MyPerformanceCounter.PerCameraDraw11Write.ShadowCascadeTriangles[cascadeIndex] = MyShadowCascades.ShadowCascadeTriangleCounter[cascadeIndex]; MyShadowCascades.ShadowCascadeTriangleCounter[cascadeIndex] = -1; } } if (MyShadows.OtherShadowsTriangleCounter >= 0) { MyPerformanceCounter.PerCameraDraw11Write.OtherShadowTriangles = MyShadows.OtherShadowsTriangleCounter; MyShadows.OtherShadowsTriangleCounter = -1; } }
// 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); }