void DisposeTexture(MyBorrowedCustomTexture custom) { ICustomTexture customTexture = custom.CustomTexture; MyManagers.CustomTextures.DisposeTex(ref customTexture); MyBorrowedTextureKey key = custom.Key; m_dictionaryCustomTextures[key].Remove(custom); m_objectPoolCustom.Deallocate(custom); }
public void DisposeTex(ref ICustomTexture texture) { if (texture == null) { return; } MyCustomTexture textureInternal = (MyCustomTexture)texture; if (m_isDeviceInit) { textureInternal.OnDeviceEnd(); } m_objectsPool.Deallocate(textureInternal); }
static void BlendHighlight(IRtvBindable target, ISrvBindable outlined, ICustomTexture fxaaTarget, IDepthStencil depthStencilCopy) { MyGpuProfiler.IC_BeginBlock("Highlight Blending"); ProfilerShort.Begin("Highlight Blending"); if (fxaaTarget != null) { MyBlendTargets.RunWithStencil( fxaaTarget.SRgb, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); MyBlendTargets.RunWithStencil( fxaaTarget.SRgb, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); } else { if (MyRender11.MultisamplingEnabled) { MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendAdditive, false, depthStencilCopy); MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendTransparent, true, depthStencilCopy); } else { MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); } } ProfilerShort.End(); MyGpuProfiler.IC_EndBlock(); }
public void DisposeTex(ref ICustomTexture texture) { if (texture == null) return; MyCustomTexture textureInternal = (MyCustomTexture)texture; if (m_isDeviceInit) textureInternal.OnDeviceEnd(); m_objectsPool.Deallocate(textureInternal); }
internal 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(); 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("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); float maxThickness = 0f; foreach (var pair in m_highlights) { 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 (MyHighlightDesc 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); } } } MyHighlightPass.Instance.End(); RC.SetBlendState(null); foreach (var outlineKey in m_keysToRemove) m_highlights.Remove(outlineKey); m_keysToRemove.SetSize(0); ISrvBindable initialSourceView = rgba8_1; IRtvBindable renderTargetview = rgba8_1; 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); }
private static void BlendHighlight(IRtvBindable target, ISrvBindable outlined, ICustomTexture fxaaTarget, IDepthStencil depthStencilCopy) { MyGpuProfiler.IC_BeginBlock("Highlight Blending"); ProfilerShort.Begin("Highlight Blending"); if (fxaaTarget != null) { MyBlendTargets.RunWithStencil( fxaaTarget.SRgb, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); MyBlendTargets.RunWithStencil( fxaaTarget.SRgb, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); } else { if (MyRender11.MultisamplingEnabled) { MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendAdditive, false, depthStencilCopy); MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendTransparent, true, depthStencilCopy); } else { MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); } } ProfilerShort.End(); MyGpuProfiler.IC_EndBlock(); }
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); }
internal 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(); 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("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); float maxThickness = 0f; foreach (var pair in m_highlights) { 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 (MyHighlightDesc 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); } } } MyHighlightPass.Instance.End(); RC.SetBlendState(null); foreach (var outlineKey in m_keysToRemove) { m_highlights.Remove(outlineKey); } m_keysToRemove.SetSize(0); ISrvBindable initialSourceView = rgba8_1; IRtvBindable renderTargetview = rgba8_1; 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); }