示例#1
0
        static MaterialBindType _GetBindType(PBRMaterial pbr, string property)
        {
            switch (property)
            {
            // case UV_PROPERTY:
            //     return MaterialBindType.UvOffset;

            case COLOR_PROPERTY:
                return(MaterialBindType.Color);

            case EMISSION_COLOR_PROPERTY:
                return(MaterialBindType.EmissionColor);
            }

            throw new NotImplementedException();
        }
示例#2
0
        static string _GetProperty(PBRMaterial pbr, MaterialBindType bindType)
        {
            switch (bindType)
            {
            // case MaterialBindType.UvOffset:
            // case MaterialBindType.UvScale:
            //     return UV_PROPERTY;

            case MaterialBindType.Color:
                return(COLOR_PROPERTY);

            case MaterialBindType.EmissionColor:
                return(EMISSION_COLOR_PROPERTY);
            }

            throw new NotImplementedException();
        }
示例#3
0
        static VrmLib.PBRMaterial ExportStandard(UnityEngine.Material src, GetOrCreateTextureDelegate map)
        {
            var material = new VrmLib.PBRMaterial(src.name)
            {
            };

            switch (src.GetTag("RenderType", true))
            {
            case "Transparent":
                material.AlphaMode = VrmLib.AlphaModeType.BLEND;
                break;

            case "TransparentCutout":
                material.AlphaMode   = VrmLib.AlphaModeType.MASK;
                material.AlphaCutoff = src.GetFloat("_Cutoff");
                break;

            default:
                material.AlphaMode = VrmLib.AlphaModeType.OPAQUE;
                break;
            }

            if (src.HasProperty("_Color"))
            {
                material.BaseColorFactor = src.color.linear.FromUnitySrgbToLinear();
            }

            if (src.HasProperty("_MainTex"))
            {
                material.BaseColorTexture = map(src, src.GetTexture("_MainTex"), VrmLib.Texture.ColorSpaceTypes.Srgb, VrmLib.Texture.TextureTypes.Default);
            }

            if (src.HasProperty("_MetallicGlossMap"))
            {
                // float smoothness = 0.0f;
                // if (m.HasProperty("_GlossMapScale"))
                // {
                //     smoothness = m.GetFloat("_GlossMapScale");
                // }

                material.MetallicRoughnessTexture = map(
                    src,
                    src.GetTexture("_MetallicGlossMap"),
                    VrmLib.Texture.ColorSpaceTypes.Linear,
                    VrmLib.Texture.TextureTypes.MetallicRoughness)?.Texture;
                if (material.MetallicRoughnessTexture != null)
                {
                    material.MetallicFactor = 1.0f;
                    // Set 1.0f as hard-coded. See: https://github.com/vrm-c/UniVRM/issues/212.
                    material.RoughnessFactor = 1.0f;
                }
            }

            if (material.MetallicRoughnessTexture == null)
            {
                if (src.HasProperty("_Metallic"))
                {
                    material.MetallicFactor = src.GetFloat("_Metallic");
                }

                if (src.HasProperty("_Glossiness"))
                {
                    material.RoughnessFactor = 1.0f - src.GetFloat("_Glossiness");
                }
            }

            if (src.HasProperty("_BumpMap"))
            {
                material.NormalTexture = map(src, src.GetTexture("_BumpMap"), VrmLib.Texture.ColorSpaceTypes.Linear, VrmLib.Texture.TextureTypes.NormalMap)?.Texture;

                if (src.HasProperty("_BumpScale"))
                {
                    material.NormalTextureScale = src.GetFloat("_BumpScale");
                }
            }

            if (src.HasProperty("_OcclusionMap"))
            {
                material.OcclusionTexture = map(src, src.GetTexture("_OcclusionMap"), VrmLib.Texture.ColorSpaceTypes.Linear, VrmLib.Texture.TextureTypes.Occlusion)?.Texture;

                if (src.HasProperty("_OcclusionStrength"))
                {
                    material.OcclusionTextureStrength = src.GetFloat("_OcclusionStrength");
                }
            }

            if (src.IsKeywordEnabled("_EMISSION"))
            {
                if (src.HasProperty("_EmissionColor"))
                {
                    var color = src.GetColor("_EmissionColor");
                    if (color.maxColorComponent > 1)
                    {
                        color /= color.maxColorComponent;
                    }
                    material.EmissiveFactor = new System.Numerics.Vector3(color.r, color.g, color.b);
                }

                if (src.HasProperty("_EmissionMap"))
                {
                    material.EmissiveTexture = map(src, src.GetTexture("_EmissionMap"), VrmLib.Texture.ColorSpaceTypes.Srgb, VrmLib.Texture.TextureTypes.Emissive)?.Texture;
                }
            }

            return(material);
        }