public MyRenderMeshMaterial Clone()
        {
            MyRenderMeshMaterial newMaterial = new MyRenderMeshMaterial();

            newMaterial.m_contentDir = m_contentDir;
            newMaterial.m_diffuseTex = m_diffuseTex;
            newMaterial.m_normalTex  = m_normalTex;

            newMaterial.m_specularIntensity = m_specularIntensity;
            newMaterial.m_specularPower     = m_specularPower;
            newMaterial.m_specularColor     = m_specularColor;
            newMaterial.m_diffuseColor      = m_diffuseColor;

            newMaterial.m_materialName      = m_materialName;
            newMaterial.m_diffuseName       = m_diffuseName;
            newMaterial.m_normalName        = m_normalName;
            newMaterial.m_hasNormalTexture  = m_hasNormalTexture;
            newMaterial.m_drawTechnique     = m_drawTechnique;
            newMaterial.m_emissiveUVAnim    = m_emissiveUVAnim;
            newMaterial.m_emissivityEnabled = m_emissivityEnabled;

            newMaterial.m_loadedContent = m_loadedContent;
            newMaterial.m_diffuseUVAnim = m_diffuseUVAnim;

            newMaterial.Enabled         = Enabled;
            newMaterial.EnableColorMask = EnableColorMask;
            newMaterial.m_emissivity    = m_emissivity;
            newMaterial.HashCode        = HashCode;

            return(newMaterial);
        }
Exemplo n.º 2
0
 internal void Clear()
 {
     RenderObject   = null;
     Material       = null;
     IndexBuffer    = null;
     VertexBuffer   = null;
     InstanceBuffer = null;
 }
        public MyRenderMeshMaterial Clone()
        {
            MyRenderMeshMaterial newMaterial = new MyRenderMeshMaterial();

            newMaterial.m_contentDir = m_contentDir;
            newMaterial.m_diffuseTex = m_diffuseTex;
            newMaterial.m_normalTex = m_normalTex;

            newMaterial.m_specularIntensity = m_specularIntensity;
            newMaterial.m_specularPower = m_specularPower;
            newMaterial.m_specularColor = m_specularColor;
            newMaterial.m_diffuseColor = m_diffuseColor;

            newMaterial.m_materialName = m_materialName;
            newMaterial.m_diffuseName = m_diffuseName;
            newMaterial.m_normalName = m_normalName;
            newMaterial.m_hasNormalTexture = m_hasNormalTexture;
            newMaterial.m_drawTechnique = m_drawTechnique;
            newMaterial.m_emissiveUVAnim = m_emissiveUVAnim;
            newMaterial.m_emissivityEnabled = m_emissivityEnabled;

            newMaterial.m_loadedContent = m_loadedContent;
            newMaterial.m_diffuseUVAnim = m_diffuseUVAnim;

            newMaterial.Enabled = Enabled;
            newMaterial.EnableColorMask = EnableColorMask;
            newMaterial.m_emissivity = m_emissivity;
            newMaterial.HashCode = HashCode;

            return newMaterial;
        }
Exemplo n.º 4
0
        public override void GetRenderElementsForShadowmap(MyLodTypeEnum lodTypeEnum, List <MyRender.MyRenderElement> renderElements, List <MyRender.MyRenderElement> transparentRenderElements)
        {
            MyRenderModel model;

            int lodIndex = m_lods.Count > (int)lodTypeEnum ? (int)lodTypeEnum : 0;

            if (ShadowBoxLod && lodTypeEnum == MyLodTypeEnum.LOD1)
            {
                model = MyDebugDraw.ModelBoxLowRes;
            }
            else
            {
                model = m_lods[lodIndex].ShadowModel == null ? m_lods[lodIndex].Model : m_lods[lodIndex].ShadowModel;
            }

            if (model == null || model.LoadState != LoadState.Loaded)
            {
                return;
            }

            var drawMatrix = GetWorldMatrixForDraw();

            if (m_drawTechnique == MyMeshDrawTechnique.GLASS)
            {
                int meshCount = model.GetMeshList().Count;
                for (int i = 0; i < meshCount; i++)
                {
                    MyRenderMesh mesh = model.GetMeshList()[i];

                    MyRenderMeshMaterial material = mesh.Material;

                    if (!material.Enabled)
                    {
                        continue;
                    }

                    VRageRender.MyRender.MyRenderElement renderElement;
                    VRageRender.MyRender.AllocateRenderElement(out renderElement);

                    if (!MyRender.IsRenderOverloaded)
                    {
                        //renderElement.DebugName = entity.Name;
                        renderElement.RenderObject = this;

                        renderElement.VertexBuffer      = model.VertexBuffer;
                        renderElement.IndexBuffer       = model.IndexBuffer;
                        renderElement.VertexCount       = model.GetVerticesCount();
                        renderElement.VertexDeclaration = model.GetVertexDeclaration();
                        renderElement.VertexStride      = model.GetVertexStride();
                        renderElement.InstanceBuffer    = null;
                        renderElement.BonesUsed         = mesh.BonesUsed;

                        renderElement.IndexStart = mesh.IndexStart;
                        renderElement.TriCount   = mesh.TriCount;

                        renderElement.WorldMatrixForDraw = drawMatrix;
                        renderElement.WorldMatrix        = WorldMatrix;

                        renderElement.Material      = material;
                        renderElement.DrawTechnique = m_drawTechnique == MyMeshDrawTechnique.MESH || m_drawTechnique == MyMeshDrawTechnique.GLASS ? material.DrawTechnique : m_drawTechnique;
                        renderElement.Color         = EntityColor * material.DiffuseColor;
                        renderElement.Dithering     = EntityDithering;
                        renderElement.ColorMaskHSV  = EntityColorMaskHSV;


                        if (material.DrawTechnique == MyMeshDrawTechnique.GLASS)
                        {
                            renderElement.Dithering = mesh.GlassDithering;
                        }
                        else
                        {
                            renderElement.Dithering = 0;
                        }


                        if (m_instanceBuffer != null)
                        {
                            renderElement.VertexStride      = m_lods[lodIndex].VertexStride;
                            renderElement.VertexDeclaration = m_lods[lodIndex].VertexDeclaration;
                            renderElement.InstanceBuffer    = m_instanceBuffer.InstanceBuffer;
                            renderElement.InstanceStart     = m_instanceStart;
                            renderElement.InstanceCount     = m_instanceCount;
                            renderElement.InstanceStride    = m_instanceBuffer.Stride;
                            renderElement.DrawTechnique     = model.BoneIndices.Length > 0 ? MyMeshDrawTechnique.MESH_INSTANCED_SKINNED : MyMeshDrawTechnique.MESH_INSTANCED;
                        }

                        Debug.Assert(renderElement.VertexBuffer != null, "Vertex buffer cannot be null!");
                        Debug.Assert(renderElement.IndexBuffer != null, "Index buffer cannot be null!");

                        if (material.DrawTechnique == MyMeshDrawTechnique.HOLO)
                        {
                            if (transparentRenderElements != null)
                            {
                                transparentRenderElements.Add(renderElement);
                            }
                        }
                        else
                        {
                            renderElements.Add(renderElement);
                        }
                    }
                }
            }
            else
            {
                if (!MyRender.IsRenderOverloaded)
                {
                    int  meshCount      = model.GetMeshList().Count;
                    bool separateMeshes = false;
                    for (int i = 0; i < meshCount; i++)
                    {
                        MyRenderMesh mesh = model.GetMeshList()[i];
                        if (mesh.BonesUsed != null)
                        {
                            separateMeshes = true;
                            break;
                        }
                    }

                    if (!separateMeshes)
                    {
                        MyRender.MyRenderElement renderElement;
                        MyRender.AllocateRenderElement(out renderElement);

                        renderElement.RenderObject = this;

                        renderElement.VertexBuffer      = model.VertexBuffer;
                        renderElement.IndexBuffer       = model.IndexBuffer;
                        renderElement.VertexCount       = model.GetVerticesCount();
                        renderElement.VertexDeclaration = model.GetVertexDeclaration();
                        renderElement.VertexStride      = model.GetVertexStride();
                        renderElement.InstanceBuffer    = null;
                        renderElement.Dithering         = 0;
                        renderElement.BonesUsed         = null;

                        if (m_instanceBuffer != null)
                        {
                            renderElement.VertexStride      = m_lods[lodIndex].VertexStride;
                            renderElement.VertexDeclaration = m_lods[lodIndex].VertexDeclaration;
                            renderElement.InstanceBuffer    = m_instanceBuffer.InstanceBuffer;
                            renderElement.InstanceStart     = m_instanceStart;
                            renderElement.InstanceCount     = m_instanceCount;
                            renderElement.InstanceStride    = m_instanceBuffer.Stride;
                        }

                        renderElement.IndexStart = 0;
                        if (renderElement.IndexBuffer != null)
                        {
                            renderElement.TriCount = model.GetTrianglesCount();
                        }

                        //renderElement.DebugName = entity.Name;
                        renderElement.WorldMatrix        = WorldMatrix;
                        renderElement.WorldMatrixForDraw = drawMatrix;

                        renderElements.Add(renderElement);
                    }
                    else
                    {
                        for (int i = 0; i < meshCount; i++)
                        {
                            MyRenderMesh mesh = model.GetMeshList()[i];

                            VRageRender.MyRender.MyRenderElement renderElement;
                            VRageRender.MyRender.AllocateRenderElement(out renderElement);

                            renderElement.RenderObject = this;

                            renderElement.VertexBuffer      = model.VertexBuffer;
                            renderElement.IndexBuffer       = model.IndexBuffer;
                            renderElement.VertexCount       = model.GetVerticesCount();
                            renderElement.VertexDeclaration = model.GetVertexDeclaration();
                            renderElement.VertexStride      = model.GetVertexStride();
                            renderElement.InstanceBuffer    = null;
                            renderElement.Dithering         = 0;

                            renderElement.BonesUsed = mesh.BonesUsed;

                            renderElement.IndexStart = mesh.IndexStart;
                            renderElement.TriCount   = mesh.TriCount;

                            if (m_instanceBuffer != null)
                            {
                                renderElement.VertexStride      = m_lods[lodIndex].VertexStride;
                                renderElement.VertexDeclaration = m_lods[lodIndex].VertexDeclaration;
                                renderElement.InstanceBuffer    = m_instanceBuffer.InstanceBuffer;
                                renderElement.InstanceStart     = m_instanceStart;
                                renderElement.InstanceCount     = m_instanceCount;
                                renderElement.InstanceStride    = m_instanceBuffer.Stride;
                                renderElement.DrawTechnique     = model.BoneIndices.Length > 0 ? MyMeshDrawTechnique.MESH_INSTANCED_SKINNED : MyMeshDrawTechnique.MESH_INSTANCED;
                            }

                            renderElement.WorldMatrix        = WorldMatrix;
                            renderElement.WorldMatrixForDraw = drawMatrix;

                            renderElements.Add(renderElement);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        internal void CollectRenderElements(List <VRageRender.MyRender.MyRenderElement> renderElements, List <VRageRender.MyRender.MyRenderElement> transparentRenderElements, MyRenderModel model, List <MyRenderMeshMaterial> materials, int lodIndex)
        {
            if (model.LoadState == LoadState.Unloaded)
            {
                //model.LoadInDraw(LoadingMode.Background);
                model.LoadInDraw(LoadingMode.Immediate);
                return;
            }
            if (model.LoadState == LoadState.Loading)
            {
                return;
            }

            if (m_instanceBuffer != null && m_instanceCount == 0)
            {
                return;
            }

            var drawMatrix = GetWorldMatrixForDraw();

            int meshCount = model.GetMeshList().Count;

            for (int i = 0; i < meshCount; i++)
            {
                MyRenderMesh mesh = model.GetMeshList()[i];

                MyRenderMeshMaterial material = model.HasSharedMaterials ? mesh.Material : materials[i];

                if (!material.Enabled)
                {
                    continue;
                }

                if (material.DrawTechnique == MyMeshDrawTechnique.GLASS && EntityDithering == 0)
                {
                    m_drawTechnique = MyMeshDrawTechnique.GLASS;
                    continue;
                }

                //Preload needs to be here because of reloadcontent
                material.PreloadTexture(LoadingMode.Background);

                VRageRender.MyRender.MyRenderElement renderElement;
                VRageRender.MyRender.AllocateRenderElement(out renderElement);

                if (!MyRender.IsRenderOverloaded)
                {
                    //renderElement.DebugName = entity.Name;
                    renderElement.RenderObject = this;

                    renderElement.VertexBuffer      = model.VertexBuffer;
                    renderElement.IndexBuffer       = model.IndexBuffer;
                    renderElement.VertexCount       = model.GetVerticesCount();
                    renderElement.VertexDeclaration = model.GetVertexDeclaration();
                    renderElement.VertexStride      = model.GetVertexStride();
                    renderElement.InstanceBuffer    = null;
                    renderElement.BonesUsed         = mesh.BonesUsed;

                    renderElement.IndexStart = mesh.IndexStart;
                    renderElement.TriCount   = mesh.TriCount;

                    renderElement.WorldMatrixForDraw = drawMatrix;
                    renderElement.WorldMatrix        = WorldMatrix;

                    renderElement.Material      = material;
                    renderElement.DrawTechnique = m_drawTechnique == MyMeshDrawTechnique.MESH || m_drawTechnique == MyMeshDrawTechnique.GLASS ? material.DrawTechnique : m_drawTechnique;
                    renderElement.Color         = EntityColor * material.DiffuseColor;
                    renderElement.Dithering     = mesh.GlassDithering == 0 ? EntityDithering : mesh.GlassDithering;
                    renderElement.ColorMaskHSV  = EntityColorMaskHSV;

                    if (m_instanceBuffer != null)
                    {
                        renderElement.VertexStride      = m_lods[lodIndex].VertexStride;
                        renderElement.VertexDeclaration = m_lods[lodIndex].VertexDeclaration;
                        renderElement.InstanceBuffer    = m_instanceBuffer.InstanceBuffer;
                        renderElement.InstanceStart     = m_instanceStart;
                        renderElement.InstanceCount     = m_instanceCount;
                        renderElement.InstanceStride    = m_instanceBuffer.Stride;

                        if (m_instanceBuffer.Type == MyRenderInstanceBufferType.Generic)
                        {
                            renderElement.DrawTechnique = renderElement.DrawTechnique == MyMeshDrawTechnique.ALPHA_MASKED ? MyMeshDrawTechnique.MESH_INSTANCED_GENERIC_MASKED : MyMeshDrawTechnique.MESH_INSTANCED_GENERIC;
                        }
                        else
                        {
                            renderElement.DrawTechnique = model.BoneIndices.Length > 0 ? MyMeshDrawTechnique.MESH_INSTANCED_SKINNED : MyMeshDrawTechnique.MESH_INSTANCED;
                        }
                    }

                    Debug.Assert(renderElement.VertexBuffer != null, "Vertex buffer cannot be null!");
                    Debug.Assert(renderElement.IndexBuffer != null, "Index buffer cannot be null!");

                    if (material.DrawTechnique == MyMeshDrawTechnique.HOLO)
                    {
                        if (transparentRenderElements != null)
                        {
                            transparentRenderElements.Add(renderElement);
                        }
                    }
                    else
                    {
                        renderElements.Add(renderElement);
                    }
                }
            }
        }
        /// <summary>
        /// c-tor - generic way for collecting resources
        /// </summary>
        /// <param name="meshInfo"></param>
        /// assetName - just for debug output
        public MyRenderMesh(MyMeshPartInfo meshInfo, string assetName)
        {
            string contentDir = "";

            if (Path.IsPathRooted(assetName) && assetName.ToLower().Contains("models"))
                contentDir = assetName.Substring(0, assetName.ToLower().IndexOf("models"));

            MyMaterialDescriptor matDesc = meshInfo.m_MaterialDesc;
            if (matDesc != null)
            {
                bool hasNormalTexture = true;

                string normalPath = null;
                string diffusePath;
                matDesc.Textures.TryGetValue("DiffuseTexture", out diffusePath);
                matDesc.Textures.TryGetValue("NormalTexture", out normalPath);

                if (String.IsNullOrEmpty(normalPath) && !String.IsNullOrEmpty(diffusePath))
                {
                    if(String.IsNullOrEmpty(diffusePath))
                    {
                        diffusePath = null;
                        normalPath = null;
                    }
                    else
                    {
                        string ext = Path.GetExtension(diffusePath);
                        string deMatch = C_POSTFIX_DIFFUSE_EMISSIVE + ext;
                        string meMatch = C_POSTFIX_MASK_EMISSIVE + ext;

                        if (diffusePath.EndsWith(deMatch))
                            normalPath = diffusePath.Substring(0, diffusePath.Length - deMatch.Length) + C_POSTFIX_NORMAL_SPECULAR + ext;
                        else if (diffusePath.EndsWith(meMatch))
                            normalPath = diffusePath.Substring(0, diffusePath.Length - meMatch.Length) + C_POSTFIX_NORMAL_SPECULAR + ext;
                        else
                            normalPath = null;
                    }
                }

                Material = new MyRenderMeshMaterial(matDesc.MaterialName,
                                                          contentDir,
                                                          diffusePath,
                                                          normalPath,
                                                          matDesc.SpecularPower,
                                                          matDesc.SpecularIntensity,
                                                          hasNormalTexture,
                                                          matDesc.DiffuseColor,
                                                          matDesc.ExtraData);

                Material.DrawTechnique = meshInfo.Technique;

                m_assetName = assetName;
            }
            else
            {
                //It is OK because ie. collision meshes dont have materials
                //MyCommonDebugUtils.AssertRelease(false, String.Format("Model {0} has bad material for mesh.", assetName));
                Trace.TraceWarning("Model with null material: " + assetName);

                //We define at least debug material
                VRageMath.Vector3 color = VRageMath.Color.Pink.ToVector3();
                Material = new MyRenderMeshMaterial("", "", @"Textures\Models\Debug\white_de.dds", @"Textures\Models\Debug\white_ns.dds", 0, 0, true, color, color);
            }
        }
Exemplo n.º 7
0
        public static void Draw()
        {
            if (!Visible)
            {
                return;
            }

            MyRenderModel model = MyRenderModels.GetModel(Model);//MySession.Static.PlayerShip.CockpitGlassModelEnum);

            RasterizerState.CullNone.Apply();

            MyStateObjects.DepthStencil_StencilReadOnly.Apply();

            BlendState.NonPremultiplied.Apply();

            MyEffectCockpitGlass effect = (MyEffectCockpitGlass)MyRender.GetEffect(MyEffects.CockpitGlass);

            effect.SetGlassDirtLevelAlpha(new Vector4(GlassDirtAlpha, 0, 0, 0));

            var     inMatrix = PlayerHeadForCockpitInteriorWorldMatrix;
            MatrixD drawMatrix;

            MatrixD.Multiply(ref inMatrix, ref MyRenderCamera.InversePositionTranslationMatrix, out drawMatrix);

            effect.SetWorldMatrix((Matrix)drawMatrix);
            effect.SetViewMatrix((Matrix)MyRenderCamera.ViewMatrix);

            Matrix projection = MyRenderCamera.ProjectionMatrixForNearObjects;

            effect.SetWorldViewProjectionMatrix((Matrix)(drawMatrix * MyRenderCamera.ViewMatrixAtZero * projection));

            MyRenderMeshMaterial cockpitMaterial = model.GetMeshList()[0].Material;

            cockpitMaterial.PreloadTexture();
            effect.SetCockpitGlassTexture(cockpitMaterial.DiffuseTexture);

            Texture depthRT = MyRender.GetRenderTarget(MyRenderTargets.Depth);

            effect.SetDepthTexture(depthRT);

            effect.SetHalfPixel(MyUtilsRender9.GetHalfPixel(depthRT.GetLevelDescription(0).Width, depthRT.GetLevelDescription(0).Height));

            Vector4 sunColor = MyRender.Sun.Color;

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));

            effect.SetDirectionToSun(-MyRender.Sun.Direction);

            effect.SetAmbientColor(Vector3.Zero);
            effect.SetReflectorPosition((Vector3)((Vector3)MyRenderCamera.Position - 4 * MyRenderCamera.ForwardVector));

            if (MyRender.RenderLightsForDraw.Count > 0)
            {
                effect.SetNearLightColor(MyRender.RenderLightsForDraw[0].Color);
                effect.SetNearLightRange(MyRender.RenderLightsForDraw[0].Range);
            }

            MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect);
            effect.SetShadowBias(0.001f);

            MyLights.UpdateEffect(effect, true);

            effect.Begin();
            model.Render();
            effect.End();

            //MyDebugDraw.DrawSphereWireframe(PlayerHeadForCockpitInteriorWorldMatrix, Vector3.One, 1);
        }
Exemplo n.º 8
0
        /// <summary>
        /// c-tor - generic way for collecting resources
        /// </summary>
        /// <param name="meshInfo"></param>
        /// assetName - just for debug output
        public MyRenderMesh(MyMeshPartInfo meshInfo, string assetName)
        {
            string contentDir = "";

            if (Path.IsPathRooted(assetName) && assetName.ToLower().Contains("models"))
            {
                contentDir = assetName.Substring(0, assetName.ToLower().IndexOf("models"));
            }

            MyMaterialDescriptor matDesc = meshInfo.m_MaterialDesc;

            if (matDesc != null)
            {
                bool hasNormalTexture = true;

                string normalPath = null;
                string diffusePath;
                matDesc.Textures.TryGetValue("DiffuseTexture", out diffusePath);
                matDesc.Textures.TryGetValue("NormalTexture", out normalPath);

                if (String.IsNullOrEmpty(normalPath) && !String.IsNullOrEmpty(diffusePath))
                {
                    if (String.IsNullOrEmpty(diffusePath))
                    {
                        diffusePath = null;
                        normalPath  = null;
                    }
                    else
                    {
                        string ext     = Path.GetExtension(diffusePath);
                        string deMatch = C_POSTFIX_DIFFUSE_EMISSIVE + ext;
                        string meMatch = C_POSTFIX_MASK_EMISSIVE + ext;

                        if (diffusePath.EndsWith(deMatch))
                        {
                            normalPath = diffusePath.Substring(0, diffusePath.Length - deMatch.Length) + C_POSTFIX_NORMAL_SPECULAR + ext;
                        }
                        else if (diffusePath.EndsWith(meMatch))
                        {
                            normalPath = diffusePath.Substring(0, diffusePath.Length - meMatch.Length) + C_POSTFIX_NORMAL_SPECULAR + ext;
                        }
                        else
                        {
                            normalPath = null;
                        }
                    }
                }

                Material = new MyRenderMeshMaterial(matDesc.MaterialName,
                                                    contentDir,
                                                    diffusePath,
                                                    normalPath,
                                                    matDesc.SpecularPower,
                                                    matDesc.SpecularIntensity,
                                                    hasNormalTexture,
                                                    matDesc.DiffuseColor,
                                                    matDesc.ExtraData);

                Material.DrawTechnique = meshInfo.Technique;

                m_assetName = assetName;
            }
            else
            {
                //It is OK because ie. collision meshes dont have materials
                //MyCommonDebugUtils.AssertRelease(false, String.Format("Model {0} has bad material for mesh.", assetName));
                Trace.TraceWarning("Model with null material: " + assetName);

                //We define at least debug material
                VRageMath.Vector3 color = VRageMath.Color.Pink.ToVector3();
                Material = new MyRenderMeshMaterial("", "", @"Textures\Models\Debug\white_de.dds", @"Textures\Models\Debug\white_ns.dds", 0, 0, true, color, color);
            }
        }