Exemplo n.º 1
0
        /// <returns>True if the section was found</returns>
        static void RecordMeshSectionCommands(MeshId model,
                                              MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                              MyHighlightDesc desc)
        {
            MeshSectionId sectionId;
            bool          found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionName, out sectionId);

            if (!found)
            {
                return;
            }

            WriteHighlightConstants(ref desc);

            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.SectionName, rendercomp, renderLod, meshes, idx);
                    return;
                }

                MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex];
                MyHighlightPass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId);
            }
        }
Exemplo n.º 2
0
        static void WriteHighlightConstants(ref MyHighlightDesc desc)
        {
            HighlightConstantsLayout constants = new HighlightConstantsLayout();

            constants.Color = desc.Color.ToVector4();
            if (desc.PulseTimeInSeconds > 0)
            {
                constants.Color.W *= (float)Math.Pow(Math.Cos(2.0 * Math.PI * MyCommon.TimerMs / desc.PulseTimeInSeconds / 1000), 2.0);
            }

            var mapping = MyMapping.MapDiscard(MyCommon.HighlightConstants);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();
        }
Exemplo n.º 3
0
        static void WriteHighlightConstants(ref MyHighlightDesc desc)
        {
            HighlightConstantsLayout constants = new HighlightConstantsLayout();

            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.HighlightConstants);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();
        }
Exemplo n.º 4
0
        static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
                                           MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                           MyHighlightDesc desc)
        {
            WriteHighlightConstants(ref desc);

            var submeshCount = lodModelId.Info.PartsNum;

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

                MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders);
                MyHighlightPass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId);
            }
        }
Exemplo n.º 5
0
        static void RecordMeshPartCommands(MeshId model, MyActor actor, MyGroupRootComponent group,
                                           MyCullProxy_2 proxy, MyHighlightDesc desc)
        {
            MeshSectionId sectionId;
            bool          found = MyMeshes.TryGetMeshSection(model, 0, desc.SectionName, out sectionId);

            if (!found)
            {
                return;
            }

            WriteHighlightConstants(ref desc);

            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.SectionName, meshes[idx].Material);
                    return;
                }

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

                MyHighlightPass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex);
            }
        }
Exemplo n.º 6
0
        private static void WriteHighlightConstants(ref MyHighlightDesc desc, ref float maxThickness)
        {
            maxThickness = Math.Max(desc.Thickness, maxThickness);
            HighlightConstantsLayout constants = new HighlightConstantsLayout();
            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.HighlightConstants);
            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();
        }
Exemplo n.º 7
0
        /// <returns>True if the section was found</returns>
        private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyHighlightDesc desc, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);
            if (!found)
                return;

            WriteHighlightConstants(ref desc, ref maxThickness);

            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;
                }

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

            return;
        }
Exemplo n.º 8
0
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyHighlightDesc desc, ref float maxThickness)
        {
            WriteHighlightConstants(ref desc, ref maxThickness);

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

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

            WriteHighlightConstants(ref desc, ref maxThickness);

            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;

                MyHighlightPass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex);
            }
        }
Exemplo n.º 10
0
        static void DrawInstanceComponent(MyInstanceComponent instanceComponent, List <MyHighlightDesc> highlightDescs)
        {
            MyRenderContext RC = MyRender11.RC;

            // common settings (combination of MyHighlightPass.cs and MyRenderingPass.cs):
            MyMapping mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants);
            Matrix    matrix  = MyRender11.Environment.Matrices.ViewProjectionAt0;

            matrix = Matrix.Transpose(matrix);
            mapping.WriteAndPosition(ref matrix);
            mapping.Unmap();

            RC.VertexShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.VertexShader.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.SetSrv(MyCommon.DITHER_8X8_SLOT, MyGeneratedTextureManager.Dithering8x8Tex);
            //RC.AllShaderStages.SetConstantBuffer(MyCommon.ALPHAMASK_VIEWS_SLOT, MyCommon.AlphamaskViewsConstants); // not used! Maybe impostors?
            RC.SetDepthStencilState(MyDepthStencilStateManager.WriteHighlightStencil, MyHighlight.HIGHLIGHT_STENCIL_MASK);
            RC.SetBlendState(null);
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
            RC.SetScreenViewport();

            RC.PixelShader.SetConstantBuffer(4, MyCommon.HighlightConstants);


            MyLod lod = instanceComponent.GetHighlightLod();
            MyInstanceLodState stateId = MyInstanceLodState.Solid;
            float stateData            = 0;

            RC.SetIndexBuffer(lod.IB);
            RC.SetVertexBuffer(0, lod.VB0);

            IConstantBuffer objectCB = GetObjectCB(RC, instanceComponent, stateData);

            RC.VertexShader.SetConstantBuffer(MyCommon.OBJECT_SLOT, objectCB);
            RC.PixelShader.SetConstantBuffer(MyCommon.OBJECT_SLOT, objectCB);

            foreach (MyHighlightDesc desc in highlightDescs)
            {
                MyHighlightDesc descRef = desc;
                WriteHighlightConstants(ref descRef);

                if (string.IsNullOrEmpty(desc.SectionName))
                {
                    foreach (var part in lod.Parts)
                    {
                        DrawHighlightedPart(RC, part, stateId);
                    }
                }
                else
                {
                    if (lod.HighlightSections != null && lod.HighlightSections.ContainsKey(desc.SectionName))
                    {
                        foreach (var part in lod.HighlightSections[desc.SectionName].Parts)
                        {
                            DrawHighlightedPart(RC, part, stateId);
                        }
                    }
                }
            }
        }