Пример #1
0
 public void SetTexture(int index)
 {
     if (visMat != null)
     {
         if (index < 0 || index > visMat.animTextures.Count)
         {
             return;
         }
         textureIndex   = index;
         currentTexture = index;
         TextureInfo tex = visMat.animTextures[index].texture;
         if (tex != null)
         {
             mat.SetTexture("_Tex0", tex.Texture);
         }
     }
     else if (visMatROM != null)
     {
         if (index < 0 || index > visMatROM.num_textures)
         {
             return;
         }
         textureIndex   = index;
         currentTexture = index;
         OpenSpace.ROM.TextureInfo tex = visMatROM.textures.Value.vmTex[index].texRef.Value.texInfo.Value;
         if (tex != null)
         {
             mat.SetTexture("_Tex0", tex.Texture);
         }
     }
 }
Пример #2
0
        public Material GetMaterial(Hint hints, GameObject gao = null)
        {
            Material mat;
            bool     billboard = (hints & Hint.Billboard) == Hint.Billboard;

            if (textures.Value != null && num_textures > 0)
            {
                TextureInfo texInfo = textures.Value.vmTex[0].texRef.Value.texInfo;
                if (texInfo.RenderTransparent || texInfo.RenderWater1 || texInfo.RenderWater2)
                {
                    if (texInfo.AlphaIsTransparency || texInfo.RenderWater1 || texInfo.RenderWater2)
                    {
                        mat = new Material(MapLoader.Loader.baseTransparentMaterial);
                    }
                    else
                    {
                        mat = new Material(MapLoader.Loader.baseLightMaterial);
                    }
                }
                else
                {
                    mat = new Material(MapLoader.Loader.baseMaterial);
                }
                mat.SetInt("_NumTextures", 1);
                string textureName = "_Tex0";
                mat.SetTexture(textureName, textures.Value.vmTex[0].texRef.Value.texInfo.Value.Texture);
                mat.SetVector(textureName + "Params", new Vector4(0,
                                                                  (scrollSpeedX != 0 || scrollSpeedY != 0) ? 1f : 0f,
                                                                  0f, 0f));
                mat.SetVector(textureName + "Params2", new Vector4(
                                  0f, 0f, ScrollX, ScrollY));
            }
            else
            {
                mat = new Material(MapLoader.Loader.baseMaterial);
            }
            Vector4 ambient, diffuse;

            if (Settings.s.platform == Settings.Platform.N64)
            {
                ambient = new Vector4(0.25f, 0.25f, 0.25f, 1f);
                diffuse = new Vector4(r / 255f, g / 255f, b / 255f, a / 255f);
            }
            else
            {
                ambient = ParseColorRGBA5551(ambientCoef) + new Vector4(0.25f, 0.25f, 0.25f, 1f);
                diffuse = ParseColorRGBA5551(diffuseCoef) + new Vector4(0, 0, 0, 1f);
            }
            mat.SetVector("_AmbientCoef", ambient);
            mat.SetVector("_DiffuseCoef", diffuse);
            if (billboard)
            {
                mat.SetFloat("_Billboard", 1f);
            }
            if (gao != null && num_textures > 1)
            {
                MultiTextureMaterial mtmat = gao.AddComponent <MultiTextureMaterial>();
                mtmat.visMatROM = this;
                mtmat.mat       = mat;
            }
            return(mat);
        }