private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
                                                   MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                                   MyOutlineDesc desc, ref float maxThickness)
        {
            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            var submeshCount = lodModelId.Info.PartsNum;

            for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
            {
                var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex);

                maxThickness    = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();
                if (desc.PulseTimeInFrames > 0)
                {
                    constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.Settings.GameplayFrame / (float)desc.PulseTimeInFrames), 2.0);
                }

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[submeshIndex]);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]);
            }
        }
        /// <returns>True if the section was found</returns>
        private static bool RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
                                                      MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                                      MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool          found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);

            if (!found)
            {
                return(false);
            }

            MyMeshSectionInfo1 section = sectionId.Info;

            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                maxThickness    = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[meshes[idx].PartIndex]);

                MyRenderableProxy proxy = renderLod.RenderableProxies[meshes[idx].PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, meshes[idx].PartSubmeshIndex);
            }

            return(true);
        }
        private static void RecordMeshPartCommands(MeshId model, MyActor actor, MyGroupRootComponent group,
                                                   MyCullProxy_2 proxy, MyOutlineDesc desc, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool          found = MyMeshes.TryGetMeshSection(model, 0, desc.SectionIndex, out sectionId);

            if (!found)
            {
                return;
            }

            OutlineConstantsLayout constants = new OutlineConstantsLayout();

            maxThickness    = Math.Max(desc.Thickness, maxThickness);
            constants.Color = desc.Color.ToVector4();
            if (desc.PulseTimeInFrames > 0)
            {
                constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.Settings.GameplayFrame / (float)desc.PulseTimeInFrames), 2.0);
            }

            MyMeshSectionInfo1 section = sectionId.Info;

            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                MyMaterialMergeGroup materialGroup;
                found = group.TryGetMaterialGroup(meshes[idx].Material, out materialGroup);
                if (!found)
                {
                    DebugRecordMeshPartCommands(model, desc.SectionIndex, meshes[idx].Material);
                    return;
                }

                int actorIndex;
                found = materialGroup.TryGetActorIndex(actor, out actorIndex);
                if (!found)
                {
                    return;
                }

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                MyOutlinePass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex);
            }
        }
        /// <returns>True if the section was found</returns>
        private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
                                                      MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                                      MyOutlineDesc desc, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool          found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);

            if (!found)
            {
                return;
            }

            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            MyMeshSectionInfo1     section   = sectionId.Info;

            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                MyMeshSectionPartInfo1 sectionInfo = meshes[idx];
                if (renderLod.RenderableProxies.Length <= sectionInfo.PartIndex)
                {
                    DebugRecordMeshPartCommands(model, desc.SectionIndex, rendercomp, renderLod, meshes, idx);
                    return;
                }

                maxThickness    = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();
                if (desc.PulseTimeInFrames > 0)
                {
                    constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.Settings.GameplayFrame / (float)desc.PulseTimeInFrames), 2.0);
                }

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[sectionInfo.PartIndex]);

                MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId);
            }

            return;
        }
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
                                                   MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                                   MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            var submeshCount = lodModelId.Info.PartsNum;

            for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
            {
                var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex);

                maxThickness    = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[submeshIndex]);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]);
            }
        }
Exemple #6
0
        /// <returns>True if the section was found</returns>
        private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);
            if (!found)
                return;

            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            MyMeshSectionInfo1 section = sectionId.Info;
            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                MyMeshSectionPartInfo1 sectionInfo = meshes[idx];
                if (renderLod.RenderableProxies.Length <= sectionInfo.PartIndex)
                {
                    DebugRecordMeshPartCommands(model, desc.SectionIndex, rendercomp, renderLod, meshes, idx);
                    return;
                }

                maxThickness = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();
                if (desc.PulseTimeInFrames > 0)
                    constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0);

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[sectionInfo.PartIndex].HighlightShaders);

                MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId);
            }

            return;
        }
Exemple #7
0
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref float maxThickness)
        {
            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            var submeshCount = lodModelId.Info.PartsNum;
            for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
            {
                var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex);

                maxThickness = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();
                if (desc.PulseTimeInFrames > 0)
                    constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0);

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId);
            }
        }
Exemple #8
0
        private static void RecordMeshPartCommands(MeshId model, MyActor actor, MyGroupRootComponent group,
            MyCullProxy_2 proxy, MyOutlineDesc desc, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool found = MyMeshes.TryGetMeshSection(model, 0, desc.SectionIndex, out sectionId);
            if (!found)
                return;

            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            maxThickness = Math.Max(desc.Thickness, maxThickness);
            constants.Color = desc.Color.ToVector4();
            if (desc.PulseTimeInFrames > 0)
                constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0);

            MyMeshSectionInfo1 section = sectionId.Info;
            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                MyMaterialMergeGroup materialGroup;
                found = group.TryGetMaterialGroup(meshes[idx].Material, out materialGroup);
                if (!found)
                {
                    DebugRecordMeshPartCommands(model, desc.SectionIndex, meshes[idx].Material);
                    return;
                }

                int actorIndex;
                found = materialGroup.TryGetActorIndex(actor, out actorIndex);
                if (!found)
                    return;

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                MyOutlinePass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex);
            }
        }
        internal static void 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 = MyEnvironment.ViewProjectionAt0;
            MyOutlinePass.Instance.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);

            MyOutlinePass.Instance.PerFrame();
            MyOutlinePass.Instance.Begin();

            RC.Clear();
            RC.DeviceContext.VertexShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.DeviceContext.GeometryShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.DeviceContext.PixelShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.DeviceContext.ComputeShader.SetShaderResources(0, null, null, null, null, null, null);

            if (MyRender11.MultisamplingEnabled)
            {
                RC.DeviceContext.ClearRenderTargetView(MyRender11.m_rgba8_ms.m_RTV, new SharpDX.Color4(0, 0, 0, 0));

                RC.DeviceContext.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_ms.m_RTV);
            }
            else
            {
                RC.DeviceContext.ClearRenderTargetView(MyRender11.m_rgba8_1.m_RTV, new SharpDX.Color4(0, 0, 0, 0));

                RC.DeviceContext.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_1.m_RTV);
            }

            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            float maxThickness = 0f;

            foreach (var pair in m_outlines)
            {
                MyActor actor = MyIDTracker<MyActor>.FindByID(pair.Key);
                if (actor == null)  // If an actor has been removed without removing outlines, just remove the outlines too
                {
                    m_keysToRemove.Add(pair.Key);
                    continue;
                }

                var renderableComponent = actor.GetRenderable();
                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 (descriptor.SectionIndex == -1)
                    {
                        RecordMeshPartCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref constants, ref maxThickness);
                    }
                    else
                    {
                        RecordMeshSectionCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref constants, ref maxThickness);
                    }
                }
            }

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

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

            m_keysToRemove.SetSize(0);

            ShaderResourceView initialSourceView = MyRender11.MultisamplingEnabled ? MyRender11.m_rgba8_ms.m_SRV : MyRender11.m_rgba8_1.m_SRV;
            RenderTargetView renderTargetview = MyRender11.MultisamplingEnabled ? MyRender11.m_rgba8_ms.m_RTV : MyRender11.m_rgba8_1.m_RTV;

            if (maxThickness > 0)
            {
                MyBlur.Run(renderTargetview, MyRender11.m_rgba8_2.m_RTV, MyRender11.m_rgba8_2.m_SRV, initialSourceView,
                    (int)Math.Round(5 * maxThickness),
                    MyBlur.MyBlurDensityFunctionType.Exponential, 0.25f,
                    null, MyFoliageRenderingPass.GrassStencilMask);
            }

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
        /// <returns>True if the section was found</returns>
        private static bool RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);
            if (!found)
                return false;

            MyMeshSectionInfo1 section = sectionId.Info;
            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                maxThickness = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[meshes[idx].PartIndex]);

                MyRenderableProxy proxy = renderLod.RenderableProxies[meshes[idx].PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, meshes[idx].PartSubmeshIndex);
            }

            return true;
        }
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            var submeshCount = lodModelId.Info.PartsNum;
            for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
            {
                var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex);

                maxThickness = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[submeshIndex]);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]);
            }
        }
        internal static void 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 = MyEnvironment.ViewProjectionAt0;
            MyOutlinePass.Instance.Viewport       = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);

            MyOutlinePass.Instance.PerFrame();
            MyOutlinePass.Instance.Begin();

            RC.Clear();
            RC.DeviceContext.VertexShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.DeviceContext.GeometryShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.DeviceContext.PixelShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.DeviceContext.ComputeShader.SetShaderResources(0, null, null, null, null, null, null);

            if (MyRender11.MultisamplingEnabled)
            {
                RC.DeviceContext.ClearRenderTargetView(MyRender11.m_rgba8_ms.m_RTV, new SharpDX.Color4(0, 0, 0, 0));

                RC.DeviceContext.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_ms.m_RTV);
            }
            else
            {
                RC.DeviceContext.ClearRenderTargetView(MyRender11.m_rgba8_1.m_RTV, new SharpDX.Color4(0, 0, 0, 0));

                RC.DeviceContext.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_1.m_RTV);
            }

            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            float maxThickness = 0f;

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

                if (actor == null)  // If an actor has been removed without removing outlines, just remove the outlines too
                {
                    m_keysToRemove.Add(pair.Key);
                    continue;
                }

                var renderableComponent = actor.GetRenderable();
                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 (descriptor.SectionIndex == -1)
                    {
                        RecordMeshPartCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref constants, ref maxThickness);
                    }
                    else
                    {
                        RecordMeshSectionCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref constants, ref maxThickness);
                    }
                }
            }

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

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

            m_keysToRemove.SetSize(0);

            ShaderResourceView initialSourceView = MyRender11.MultisamplingEnabled ? MyRender11.m_rgba8_ms.m_SRV : MyRender11.m_rgba8_1.m_SRV;
            RenderTargetView   renderTargetview  = MyRender11.MultisamplingEnabled ? MyRender11.m_rgba8_ms.m_RTV : MyRender11.m_rgba8_1.m_RTV;

            if (maxThickness > 0)
            {
                MyBlur.Run(renderTargetview, MyRender11.m_rgba8_2.m_RTV, MyRender11.m_rgba8_2.m_SRV, initialSourceView,
                           (int)Math.Round(5 * maxThickness),
                           MyBlur.MyBlurDensityFunctionType.Exponential, 0.25f,
                           null, MyFoliageRenderingPass.GrassStencilMask);
            }

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