internal static void Run(IRtvBindable dst, MyGBuffer gbuffer, ISrvBindable resolvedDepth) { RC.ClearRtv(dst, new SharpDX.Color4(1, 1, 1, 1)); var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2)); var mapping = MyMapping.MapDiscard(paramsCB); mapping.WriteAndPosition(ref Params.Data); FillRandomVectors(mapping); mapping.Unmap(); if (!MyStereoRender.Enable) { RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.BindRawCB_FrameConstants(RC); } RC.AllShaderStages.SetConstantBuffer(1, paramsCB); RC.PixelShader.Set(m_ps); RC.SetRtv(dst); RC.PixelShader.SetSrvs(0, gbuffer); RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); RC.PixelShader.SetSrv(5, resolvedDepth); RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); DrawFullscreenQuad(); RC.ResetTargets(); }
static void SetupOIT(IUavTexture accumTarget, IUavTexture coverageTarget, bool clear) { RC.SetScreenViewport(); RC.SetBlendState(MyBlendStateManager.BlendWeightedTransparency); if (clear) { RC.ClearRtv(accumTarget, new SharpDX.Color4(0, 0, 0, 0)); RC.ClearRtv(coverageTarget, new SharpDX.Color4(1, 1, 1, 1));//0,0,0,0)); } RC.SetRtvs(MyGBuffer.Main.ResolvedDepthStencil, MyDepthStencilAccess.ReadOnly, accumTarget, coverageTarget); }
internal void Clear(VRageMath.Color clearColor) { RC.ClearDsv(DepthStencil, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, MyRender11.DepthClearValue, 0); var v3 = clearColor.ToVector3(); RC.ClearRtv(m_gbuffer0, new Color4(v3.X, v3.Y, v3.Z, 1)); RC.ClearRtv(m_gbuffer1, Color4.Black); RC.ClearRtv(m_gbuffer2, Color4.Black); RC.ClearRtv(m_lbuffer, Color4.Black); }
static void SetupOIT(IUavTexture accumTarget, IUavTexture coverageTarget, bool clear) { RC.SetScreenViewport(); RC.SetBlendState(MyBlendStateManager.BlendWeightedTransparency); if (clear) { RC.ClearRtv(accumTarget, new SharpDX.Color4(0, 0, 0, 0)); RC.ClearRtv(coverageTarget, new SharpDX.Color4(1, 1, 1, 1));//0,0,0,0)); } if (MyRender11.MultisamplingEnabled) { RC.SetRtvs(MyScreenDependants.m_resolvedDepth, MyDepthStencilAccess.ReadOnly, accumTarget, coverageTarget); } else { RC.SetRtvs(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, accumTarget, coverageTarget); } }
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(); }
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); }
/// <param name="clearColor">Color used to clear render targets. Defaults to black</param> internal static void Run(IRtvBindable renderTarget, IRtvTexture intermediate, ISrvBindable initialResourceView, int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f, IDepthStencilState depthStencilState = null, int stencilRef = 0x0, Color4 clearColor = default(Color4), float depthDiscardThreshold = 0.0f, MyViewport?viewport = null) { ProfilerShort.Begin("MyBlur.Run"); MyGpuProfiler.IC_BeginBlock("MyBlur.Run"); Debug.Assert(initialResourceView != null); Debug.Assert(intermediate != null); Debug.Assert(renderTarget != null); int shaderKey = InitShaders(densityFunctionType, maxOffset, depthDiscardThreshold); RC.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer); BlurConstants constants = new BlurConstants { DistributionWeight = WeightParameter, StencilRef = stencilRef, }; var mapping = MyMapping.MapDiscard(m_blurConstantBuffer); mapping.WriteAndPosition(ref constants); mapping.Unmap(); // Horizontal pass // NOTE: DepthStencilState is not used here because the resulted target // would not be usable to perform vertical pass. DepthStencil is stil // bindinded as SRV since it is sampled in the shader RC.ClearRtv(intermediate, clearColor); RC.SetRtv(intermediate); RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth); RC.PixelShader.SetSrv(4, MyGBuffer.Main.DepthStencil.SrvStencil); RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); RC.PixelShader.SetSrv(5, initialResourceView); RC.PixelShader.Set(m_blurShaders[shaderKey].Item1); MyScreenPass.DrawFullscreenQuad(viewport); RC.PixelShader.SetSrv(5, null); // Vertical pass RC.ClearRtv(renderTarget, clearColor); if (depthStencilState == null) { RC.SetRtv(renderTarget); } else { RC.SetDepthStencilState(depthStencilState, stencilRef); RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget); } RC.PixelShader.SetSrv(5, intermediate); RC.PixelShader.Set(m_blurShaders[shaderKey].Item2); MyScreenPass.DrawFullscreenQuad(viewport); RC.PixelShader.SetSrv(0, null); RC.PixelShader.SetSrv(4, null); RC.PixelShader.SetSrv(5, null); RC.SetRtv(null); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); }
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); }