diff --git a/Runtime/Scripts/Export/StandardMaterialExport.cs b/Runtime/Scripts/Export/StandardMaterialExport.cs index 54aea5d8..f4d4c998 100644 --- a/Runtime/Scripts/Export/StandardMaterialExport.cs +++ b/Runtime/Scripts/Export/StandardMaterialExport.cs @@ -114,7 +114,7 @@ internal static bool ConvertMaterial(UnityEngine.Material uMaterial, out Materia } if ( uMaterial.HasProperty(k_BumpMap) - && (uMaterial.IsKeywordEnabled( BuiltInMaterialGenerator.KW_NORMALMAP) + && (uMaterial.IsKeywordEnabled( Materials.Constants.kwNormalMap) || uMaterial.IsKeywordEnabled(k_KeywordBumpMap)) ) { @@ -343,8 +343,8 @@ IGltfWritable gltf // texCoord = 0 // TODO: figure out which UV set was used }; - if (material.HasProperty(MaterialGenerator.PROP_BUMP_SCALE)) { - info.scale = material.GetFloat(MaterialGenerator.PROP_BUMP_SCALE); + if (material.HasProperty(MaterialGenerator.bumpScalePropId)) { + info.scale = material.GetFloat(MaterialGenerator.bumpMapPropId); } return info; diff --git a/Runtime/Scripts/Material/BuiltInMaterialGenerator.cs b/Runtime/Scripts/Material/BuiltInMaterialGenerator.cs index dd5baf81..884d6207 100644 --- a/Runtime/Scripts/Material/BuiltInMaterialGenerator.cs +++ b/Runtime/Scripts/Material/BuiltInMaterialGenerator.cs @@ -47,7 +47,6 @@ public class BuiltInMaterialGenerator : MaterialGenerator { public const string KW_ALPHATEST_ON = "_ALPHATEST_ON"; public const string KW_EMISSION = "_EMISSION"; public const string KW_METALLIC_ROUGNESS_MAP = "_METALLICGLOSSMAP"; - public const string KW_NORMALMAP = "_NORMALMAP"; public const string KW_OCCLUSION = "_OCCLUSION"; public const string KW_SPEC_GLOSS_MAP = "_SPECGLOSSMAP"; @@ -248,7 +247,7 @@ IGltfReadable gltf bumpMapRotationPropId, bumpMapUVChannelPropId )) { - material.EnableKeyword(KW_NORMALMAP); + material.EnableKeyword(Constants.kwNormalMap); material.SetFloat(bumpScalePropId,gltfMaterial.normalTexture.scale); } diff --git a/Runtime/Scripts/Material/Constants.cs b/Runtime/Scripts/Material/Constants.cs new file mode 100644 index 00000000..99ff9e62 --- /dev/null +++ b/Runtime/Scripts/Material/Constants.cs @@ -0,0 +1,26 @@ +// Copyright 2020-2021 Andreas Atteneder +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace GLTFast.Materials { + + /// + /// Contains material related constant variables that are required for both + /// import (glTF to Unity) and export (Unity to glTF) material conversions. + /// TODO: Make const var location consistent + /// + public static class Constants { + public const string kwNormalMap = "_NORMALMAP"; + } +} diff --git a/Runtime/Scripts/Material/Constants.cs.meta b/Runtime/Scripts/Material/Constants.cs.meta new file mode 100644 index 00000000..df57073e --- /dev/null +++ b/Runtime/Scripts/Material/Constants.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2ec0d38a2880d4e2886228f3008e670d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Material/MaterialGenerator.cs b/Runtime/Scripts/Material/MaterialGenerator.cs index d3e136ee..03b5a731 100644 --- a/Runtime/Scripts/Material/MaterialGenerator.cs +++ b/Runtime/Scripts/Material/MaterialGenerator.cs @@ -45,8 +45,6 @@ protected enum MaterialType { public const string KW_UV_ROTATION = "_UV_ROTATION"; public const string KW_UV_CHANNEL_SELECT = "_UV_CHANNEL_SELECT"; - internal const string PROP_BUMP_SCALE = "_BumpScale"; - public static readonly int bumpMapPropId = Shader.PropertyToID("_BumpMap"); public static readonly int bumpMapRotationPropId = Shader.PropertyToID("_BumpMapRotation"); public static readonly int bumpMapScaleTransformPropId = Shader.PropertyToID("_BumpMap_ST"); diff --git a/Runtime/Scripts/Material/ShaderGraphMaterialGenerator.cs b/Runtime/Scripts/Material/ShaderGraphMaterialGenerator.cs index 2ff3593a..9bf3fcd6 100644 --- a/Runtime/Scripts/Material/ShaderGraphMaterialGenerator.cs +++ b/Runtime/Scripts/Material/ShaderGraphMaterialGenerator.cs @@ -304,7 +304,7 @@ public override Material GenerateMaterial(Schema.Material gltfMaterial, IGltfRea bumpMapRotationPropId, bumpMapUVChannelPropId )) { - // material.EnableKeyword(KW_NORMALMAP); + // material.EnableKeyword(Constants.kwNormalMap); material.SetFloat(bumpScalePropId,gltfMaterial.normalTexture.scale); }