Beispiel #1
0
        Dictionary <string, MyGlassMaterial> m_glassMaterials = new Dictionary <string, MyGlassMaterial>(); // key is materialName

        public MyStandardMaterial GetOrCreateStandardMaterial(string materialName, MyMeshDrawTechnique technique, string cmFilepath, string ngFilepath, string extFilepath, string alphamaskFilepath)
        {
            MyStandardMaterialKey key = new MyStandardMaterialKey
            {
                Technique         = technique,
                CmFilepath        = cmFilepath,
                NgFilepath        = ngFilepath,
                ExtFilepath       = extFilepath,
                AlphamaskFilepath = alphamaskFilepath,
            };

            MyStandardMaterial material;

            if (m_standardMaterials.TryGetValue(key, out material))
            {
                return(material);
            }

            material = new MyStandardMaterial();
            material.Init(key);

            m_standardMaterials.Add(key, material);

            return(material);
        }
Beispiel #2
0
        public bool CreateGBuffer(MyMwmData mwmData, int lodNum, ref HashSet <string> setMaterialNames)
        {
            UniqueId = MyManagers.IDGenerator.GBufferLods.Generate();
            LodNum   = lodNum;

            IB  = MyManagers.ModelBuffers.GetOrCreateIB(mwmData);
            VB0 = MyManagers.ModelBuffers.GetOrCreateVB0(mwmData);
            VB1 = MyManagers.ModelBuffers.GetOrCreateVB1(mwmData);
            VertexInputComponents = MyManagers.ModelBuffers.CreateStandardVertexInputComponents(mwmData);
            m_instanceMaterialsStrategy.Init();

            BoundingBox = mwmData.BoundindBox;

            HighlightSections = null;
            Parts             = new List <MyPart>();
            GlassParts        = null;

            int offset = 0;

            foreach (var mwmPartInfo in mwmData.PartInfos)
            {
                // Making of parts is connected to the creating index buffer. It will worth to do it much more connected in future
                int    indicesCount = mwmPartInfo.m_indices.Count;
                string materialName = mwmPartInfo.GetMaterialName();
                if (mwmPartInfo.Technique != MyMeshDrawTechnique.GLASS)
                {
                    MyMeshDrawTechnique technique        = mwmPartInfo.Technique;
                    string             cmFilepath        = MyMwmUtils.GetColorMetalTexture(mwmPartInfo, mwmData.MwmContentPath);
                    string             ngFilepath        = MyMwmUtils.GetNormalGlossTexture(mwmPartInfo, mwmData.MwmContentPath);
                    string             extFilepath       = MyMwmUtils.GetExtensionTexture(mwmPartInfo, mwmData.MwmContentPath);
                    string             alphamaskFilepath = MyMwmUtils.GetAlphamaskTexture(mwmPartInfo, mwmData.MwmContentPath);
                    MyStandardMaterial material          = MyManagers.Materials.GetOrCreateStandardMaterial(materialName, technique, cmFilepath, ngFilepath, extFilepath, alphamaskFilepath);

                    MyPart part = new MyPart();
                    part.InitForGBuffer(this, materialName, mwmData.MwmContentPath, mwmPartInfo, material, offset, indicesCount, 0);
                    Parts.Add(part);
                }
                else
                {
                    MyGlassMaterial glassMaterial = MyManagers.Materials.GetGlassMaterial(materialName);

                    MyPart part = new MyPart();
                    part.InitForGlass(this, mwmPartInfo.GetMaterialName(), glassMaterial, mwmPartInfo.Technique, offset, indicesCount, 0);
                    if (GlassParts == null)
                    {
                        GlassParts = new List <MyPart>();
                    }
                    GlassParts.Add(part); // glass parts are rendered by different pipeline than the regular "solid" geometry
                }
                offset += indicesCount;

                setMaterialNames.Add(materialName);
            }

            return(true);
        }
Beispiel #3
0
        public void InitForGBuffer(MyLod parent, string name, string contentPath, MyMeshPartInfo mwmPartInfo, MyStandardMaterial standardMaterial,
                                   int startIndex, int indicesCount, int startVertex)
        {
            MyRenderProxy.Assert(StartIndex == 0 && IndicesCount == 0 && StartVertex == 0, "The part has been initialised before!");
            MyRenderProxy.Assert(indicesCount != 0, "Invalid input");

            bool isCmTexture  = !string.IsNullOrEmpty(MyMwmUtils.GetColorMetalTexture(mwmPartInfo, contentPath));
            bool isNgTexture  = !string.IsNullOrEmpty(MyMwmUtils.GetNormalGlossTexture(mwmPartInfo, contentPath));
            bool isExtTexture = !string.IsNullOrEmpty(MyMwmUtils.GetExtensionTexture(mwmPartInfo, contentPath));

            Technique       = mwmPartInfo.Technique;
            m_shaderBundles = new MyShaderBundle[(int)MyInstanceLodState.StatesCount];
            m_shaderBundles[(int)MyInstanceLodState.Solid] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                      Technique,
                                                                                                      MyInstanceLodState.Solid,
                                                                                                      isCmTexture,
                                                                                                      isNgTexture,
                                                                                                      isExtTexture);
            m_shaderBundles[(int)MyInstanceLodState.Transition] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                           Technique,
                                                                                                           MyInstanceLodState.Transition,
                                                                                                           isCmTexture,
                                                                                                           isNgTexture,
                                                                                                           isExtTexture);
            m_shaderBundles[(int)MyInstanceLodState.Hologram] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                         Technique,
                                                                                                         MyInstanceLodState.Hologram,
                                                                                                         isCmTexture,
                                                                                                         isNgTexture,
                                                                                                         isExtTexture);
            m_shaderBundles[(int)MyInstanceLodState.Dithered] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                         Technique,
                                                                                                         MyInstanceLodState.Dithered,
                                                                                                         isCmTexture,
                                                                                                         isNgTexture,
                                                                                                         isExtTexture);
            Parent                      = parent;
            Name                        = name;
            StandardMaterial            = standardMaterial;
            GlassMaterial               = null;
            InstanceMaterialOffsetInLod = -1; // <- not used so far
            StartIndex                  = startIndex;
            IndicesCount                = indicesCount;
            StartVertex                 = startVertex;
        }