コード例 #1
0
        public override glTFMaterial ExportMaterial(Material m, TextureExporter textureExporter)
        {
            if (m.shader.name != MToon.Utils.ShaderName)
            {
                return(base.ExportMaterial(m, textureExporter));
            }

            // convert MToon intermediate value from UnityEngine.Material
            var def = MToon.Utils.GetMToonParametersFromMaterial(m);

            // gltfMaterial
            var material = new glTFMaterial
            {
                name = m.name,

                pbrMetallicRoughness = new glTFPbrMetallicRoughness
                {
                    baseColorFactor  = def.Color.LitColor.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear),
                    baseColorTexture = new glTFMaterialBaseColorTextureInfo
                    {
                        index = textureExporter.ExportSRGB(def.Color.LitMultiplyTexture),
                    },
                },

                emissiveFactor = def.Emission.EmissionColor.ToFloat3(ColorSpace.Linear, ColorSpace.Linear),
            };

            // VRMC_materials_mtoon
            var mtoon = new UniGLTF.Extensions.VRMC_materials_mtoon.VRMC_materials_mtoon
            {
                Version = "",

                TransparentWithZWrite = false,

                RenderQueueOffsetNumber = 0,

                ShadeColorFactor = new float[] { 0, 0, 0 },

                ShadeMultiplyTexture = new UniGLTF.Extensions.VRMC_materials_mtoon.TextureInfo
                {
                    Index = textureExporter.ExportSRGB(def.Color.ShadeMultiplyTexture),
                },

                // Lighting
                ShadingShiftFactor = 0,

                ShadingToonyFactor = 0,

                GiIntensityFactor = 0,

                // MatCap
                // AdditiveTexture;

                // Rim
                ParametricRimColorFactor = new float[] { 0, 0, 0 },

                // public int? RimMultiplyTexture;

                RimLightingMixFactor = 0,

                ParametricRimFresnelPowerFactor = 0,

                ParametricRimLiftFactor = 0,

                // Outline
                OutlineWidthMode = UniGLTF.Extensions.VRMC_materials_mtoon.OutlineWidthMode.none,

                OutlineWidthFactor = 0,

                // public int? OutlineWidthMultiplyTexture;

                OutlineColorFactor = new float[] { 0, 0, 0 },

                OutlineLightingMixFactor = 0,

                // public int? UvAnimationMaskTexture;

                UvAnimationScrollXSpeedFactor = 0,

                UvAnimationScrollYSpeedFactor = 0,

                UvAnimationRotationSpeedFactor = 0,
            };

            UniGLTF.Extensions.VRMC_materials_mtoon.GltfSerializer.SerializeTo(ref material.extensions, mtoon);

            return(material);
        }
コード例 #2
0
        public override glTFMaterial ExportMaterial(Material m, TextureExporter textureExporter)
        {
            if (m.shader.name != MToon.Utils.ShaderName)
            {
                return(base.ExportMaterial(m, textureExporter));
            }

            var material = new glTFMaterial
            {
                name = m.name,

                emissiveFactor = new float[] { 0, 0, 0 },
            };

            // default values
            var mtoon = new UniGLTF.Extensions.VRMC_materials_mtoon.VRMC_materials_mtoon
            {
                Version = "",

                TransparentWithZWrite = false,

                RenderQueueOffsetNumber = 0,

                ShadeFactor = new float[] { 0, 0, 0 },

                // ShadeMultiplyTexture;

                // Lighting
                ShadingShiftFactor = 0,

                ShadingToonyFactor = 0,

                LightColorAttenuationFactor = 0,

                GiIntensityFactor = 0,

                // MatCap
                // AdditiveTexture;

                // Rim
                RimFactor = new float[] { 0, 0, 0 },

                // public int? RimMultiplyTexture;

                RimLightingMixFactor = 0,

                RimFresnelPowerFactor = 0,

                RimLiftFactor = 0,

                // Outline
                OutlineWidthMode = UniGLTF.Extensions.VRMC_materials_mtoon.OutlineWidthMode.none,

                OutlineWidthFactor = 0,

                // public int? OutlineWidthMultiplyTexture;

                OutlineScaledMaxDistanceFactor = 0,

                OutlineColorMode = UniGLTF.Extensions.VRMC_materials_mtoon.OutlineColorMode.fixedColor,

                OutlineFactor = new float[] { 0, 0, 0 },

                OutlineLightingMixFactor = 0,

                // public int? UvAnimationMaskTexture;

                UvAnimationScrollXSpeedFactor = 0,

                UvAnimationScrollYSpeedFactor = 0,

                UvAnimationRotationSpeedFactor = 0,
            };

            // var prop = PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name);
            // if (prop == null)
            // {
            //     Debug.LogWarningFormat("Fail to export shader: {0}", m.shader.name);
            // }
            // else
            // {
            //     foreach (var keyword in m.shaderKeywords)
            //     {
            //         material.keywordMap.Add(keyword, m.IsKeywordEnabled(keyword));
            //     }

            //     // get properties
            //     //material.SetProp(prop);
            //     foreach (var kv in prop.Properties)
            //     {
            //         switch (kv.ShaderPropertyType)
            //         {
            //             case ShaderPropertyType.Color:
            //                 {
            //                     var value = m.GetColor(kv.Key).ToArray();
            //                     material.vectorProperties.Add(kv.Key, value);
            //                 }
            //                 break;

            //             case ShaderPropertyType.Range:
            //             case ShaderPropertyType.Float:
            //                 {
            //                     var value = m.GetFloat(kv.Key);
            //                     material.floatProperties.Add(kv.Key, value);
            //                 }
            //                 break;

            //             case ShaderPropertyType.TexEnv:
            //                 {
            //                     var texture = m.GetTexture(kv.Key);
            //                     if (texture != null)
            //                     {
            //                         var value = kv.Key == "_BumpMap"
            //                             ? textureExporter.ExportNormal(texture)
            //                             : textureExporter.ExportSRGB(texture)
            //                             ;
            //                         if (value == -1)
            //                         {
            //                             Debug.LogFormat("not found {0}", texture.name);
            //                         }
            //                         else
            //                         {
            //                             material.textureProperties.Add(kv.Key, value);
            //                         }
            //                     }

            //                     // offset & scaling
            //                     var offset = m.GetTextureOffset(kv.Key);
            //                     var scaling = m.GetTextureScale(kv.Key);
            //                     material.vectorProperties.Add(kv.Key,
            //                         new float[] { offset.x, offset.y, scaling.x, scaling.y });
            //                 }
            //                 break;

            //             case ShaderPropertyType.Vector:
            //                 {
            //                     var value = m.GetVector(kv.Key).ToArray();
            //                     material.vectorProperties.Add(kv.Key, value);
            //                 }
            //                 break;

            //             default:
            //                 throw new NotImplementedException();
            //         }
            //     }
            // }

            // foreach (var tag in TAGS)
            // {
            //     var value = m.GetTag(tag, false);
            //     if (!String.IsNullOrEmpty(value))
            //     {
            //         material.tagMap.Add(tag, value);
            //     }
            // }

            UniGLTF.Extensions.VRMC_materials_mtoon.GltfSerializer.SerializeTo(ref material.extensions, mtoon);

            return(material);
        }