private static void CreateScreenResources() { var width = m_resolution.X; var height = m_resolution.Y; var samples = Settings.User.AntialiasingMode.SamplesCount(); MyUtils.Init(ref MyGBuffer.Main); MyGBuffer.Main.Resize(width, height, samples, 0); MyLightsRendering.Resize(width, height); RemoveScreenResources(); MyHBAO.InitScreenResources(); }
internal static void UpdateFrameConstants() { // environment MyFrameConstantsLayout constants = new MyFrameConstantsLayout(); UpdateFrameConstantsInternal(MyRender11.Environment.Matrices, ref constants, MyStereoRegion.FULLSCREEN); constants.Environment.CameraPositionDelta = MyRender11.Environment.Matrices.CameraPosition - m_lastCameraPosition; m_lastCameraPosition = MyRender11.Environment.Matrices.CameraPosition; // skybox constants.Environment.BackgroundOrientation = Matrix.CreateFromQuaternion(MyRender11.Environment.Data.SkyboxOrientation); // screen constants.Screen.TilesNum = (uint)MyLightsRendering.GetTilesNum(); constants.Screen.TilesX = (uint)MyLightsRendering.GetTilesX(); // foliage constants.Foliage.ClippingScaling = new Vector4( //MyRender.Settings.GrassGeometryClippingDistance, MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance(), MyRender11.Settings.GrassGeometryScalingNearDistance, MyRender11.Settings.GrassGeometryScalingFarDistance, MyRender11.Settings.GrassGeometryDistanceScalingFactor); constants.Foliage.WindVector = new Vector3( (float)Math.Cos(MyRender11.Settings.WindAzimuth * Math.PI / 180.0), 0, (float)Math.Sin(MyRender11.Settings.WindAzimuth * Math.PI / 180.0)) * MyRender11.Settings.WindStrength; // postprocess constants.Postprocess = MyRender11.Postprocess.GetProcessedData(); // lighting data constants.EnvironmentLight = MyRender11.Environment.Data.EnvironmentLight; if (!MyRender11.DebugOverrides.Sun) { constants.EnvironmentLight.SunColorRaw = new Vector3(0, 0, 0); } // fog constants.Fog.Density = MyRender11.Environment.Fog.FogDensity; constants.Fog.Mult = MyRender11.Environment.Fog.FogMultiplier; constants.Fog.Color = MyRender11.Environment.Fog.FogColor.PackedValue; // voxels MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 0, out constants.Voxel.LodRange0.X, out constants.Voxel.LodRange0.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 1, out constants.Voxel.LodRange0.Z, out constants.Voxel.LodRange0.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 2, out constants.Voxel.LodRange1.X, out constants.Voxel.LodRange1.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 3, out constants.Voxel.LodRange1.Z, out constants.Voxel.LodRange1.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 4, out constants.Voxel.LodRange2.X, out constants.Voxel.LodRange2.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 5, out constants.Voxel.LodRange2.Z, out constants.Voxel.LodRange2.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 6, out constants.Voxel.LodRange3.X, out constants.Voxel.LodRange3.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 7, out constants.Voxel.LodRange3.Z, out constants.Voxel.LodRange3.W); // MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 0, out constants.Voxel.MassiveLodRange0.X, out constants.Voxel.MassiveLodRange0.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 1, out constants.Voxel.MassiveLodRange0.Z, out constants.Voxel.MassiveLodRange0.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 2, out constants.Voxel.MassiveLodRange1.X, out constants.Voxel.MassiveLodRange1.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 3, out constants.Voxel.MassiveLodRange1.Z, out constants.Voxel.MassiveLodRange1.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 4, out constants.Voxel.MassiveLodRange2.X, out constants.Voxel.MassiveLodRange2.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 5, out constants.Voxel.MassiveLodRange2.Z, out constants.Voxel.MassiveLodRange2.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 6, out constants.Voxel.MassiveLodRange3.X, out constants.Voxel.MassiveLodRange3.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 7, out constants.Voxel.MassiveLodRange3.Z, out constants.Voxel.MassiveLodRange3.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 8, out constants.Voxel.MassiveLodRange4.X, out constants.Voxel.MassiveLodRange4.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 9, out constants.Voxel.MassiveLodRange4.Z, out constants.Voxel.MassiveLodRange4.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 10, out constants.Voxel.MassiveLodRange5.X, out constants.Voxel.MassiveLodRange5.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 11, out constants.Voxel.MassiveLodRange5.Z, out constants.Voxel.MassiveLodRange5.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 12, out constants.Voxel.MassiveLodRange6.X, out constants.Voxel.MassiveLodRange6.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 13, out constants.Voxel.MassiveLodRange6.Z, out constants.Voxel.MassiveLodRange6.W); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 14, out constants.Voxel.MassiveLodRange7.X, out constants.Voxel.MassiveLodRange7.Y); MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 15, out constants.Voxel.MassiveLodRange7.Z, out constants.Voxel.MassiveLodRange7.W); constants.Voxel.DebugVoxelLod = MyRender11.Settings.DebugClipmapLodColor ? 1.0f : 0.0f; // debug multipliers constants.TextureDebugMultipliers = new MyTextureDebugMultipliers { AlbedoMultiplier = MyRender11.Settings.AlbedoMultiplier, AlbedoShift = MyRender11.Settings.AlbedoShift, MetalnessMultiplier = MyRender11.Settings.MetalnessMultiplier, MetalnessShift = MyRender11.Settings.MetalnessShift, GlossMultiplier = MyRender11.Settings.GlossMultiplier, GlossShift = MyRender11.Settings.GlossShift, AoMultiplier = MyRender11.Settings.AoMultiplier, AoShift = MyRender11.Settings.AoShift, EmissiveMultiplier = MyRender11.Settings.EmissiveMultiplier, EmissiveShift = MyRender11.Settings.EmissiveShift, ColorMaskMultiplier = MyRender11.Settings.ColorMaskMultiplier, ColorMaskShift = MyRender11.Settings.ColorMaskShift, }; // misc if (m_fixedTimeStep > 0) { m_frameTime = m_frameTime + m_fixedTimeStep; m_lastFrameDelta = m_fixedTimeStep; } else { float timer = TimerMs; float delta = Math.Min(timer - m_lastFrameTimer, MAX_FRAMETIME) / 1000.0f; m_frameTime += delta; m_lastFrameDelta = delta; m_lastFrameTimer = timer; } constants.FrameTimeDelta = m_lastFrameDelta; constants.FrameTime = m_frameTime; constants.RandomSeed = m_random.NextFloat(); // send constants to device var mapping = MyMapping.MapDiscard(MyCommon.FrameConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); if (MyStereoRender.Enable) { UpdateFrameConstantsInternal(MyStereoRender.EnvMatricesLeftEye, ref constants, MyStereoRegion.LEFT); mapping = MyMapping.MapDiscard(MyCommon.FrameConstantsStereoLeftEye); mapping.WriteAndPosition(ref constants); mapping.Unmap(); UpdateFrameConstantsInternal(MyStereoRender.EnvMatricesRightEye, ref constants, MyStereoRegion.RIGHT); mapping = MyMapping.MapDiscard(MyCommon.FrameConstantsStereoRightEye); mapping.WriteAndPosition(ref constants); mapping.Unmap(); } }
private static unsafe void InitSubsystems() { MyManagers.OnDeviceInit(); ResetShadows(MyShadowCascades.Settings.NewData.CascadesCount, Settings.User.ShadowQuality.ShadowCascadeResolution()); MyRender11.Init(); MyCommon.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyMeshes.Init(); MyMeshTableSrv.Init(); MyLightsRendering.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.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(); MyOcclusionQueryRenderer.Init(); OnSessionStart(); try { if (m_settings.UseStereoRendering) { var openVR = new MyOpenVR(); MyStereoStencilMask.InitUsingOpenVR(); } } catch (System.Exception e) { if (!VRage.MyCompilationSymbols.DX11ForceStereo) { throw; } MyStereoStencilMask.InitUsingUndefinedMask(); } }
// 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); }