2using System.Collections.Generic;
14 [CreateAssetMenu(menuName =
"TriLib/Mappers/Material/Standard Material Mapper", fileName =
"StandardMaterialMapper")]
20 public override Material
MaterialPreset => Resources.Load<Material>(
"Materials/Standard/TriLibStandard");
22 public override Material
AlphaMaterialPreset => Resources.Load<Material>(
"Materials/Standard/TriLibStandardAlphaCutout");
24 public override Material
AlphaMaterialPreset2 => Resources.Load<Material>(
"Materials/Standard/TriLibStandardAlpha");
26 public override Material
SpecularMaterialPreset => Resources.Load<Material>(
"Materials/Standard/TriLibStandardSpecular");
32 public override Material
LoadingMaterial => Resources.Load<Material>(
"Materials/Standard/TriLibStandardLoading");
35 public override bool IsCompatible(MaterialMapperContext materialMapperContext)
41 public override void Map(MaterialMapperContext materialMapperContext)
43 materialMapperContext.VirtualMaterial =
new VirtualMaterial();
45 CheckDiffuseColor(materialMapperContext);
46 CheckDiffuseMapTexture(materialMapperContext);
47 CheckNormalMapTexture(materialMapperContext);
48 CheckEmissionColor(materialMapperContext);
49 CheckEmissionMapTexture(materialMapperContext);
50 CheckOcclusionMapTexture(materialMapperContext);
51 CheckParallaxMapTexture(materialMapperContext);
53 if (materialMapperContext.Material.MaterialShadingSetup == MaterialShadingSetup.Specular)
55 CheckMetallicValue(materialMapperContext);
56 CheckMetallicGlossMapTexture(materialMapperContext);
57 CheckGlossinessValue(materialMapperContext);
58 CheckSpecularTexture(materialMapperContext);
62 CheckGlossinessValue(materialMapperContext);
63 CheckSpecularTexture(materialMapperContext);
64 CheckMetallicValue(materialMapperContext);
65 CheckMetallicGlossMapTexture(materialMapperContext);
68 BuildMaterial(materialMapperContext);
71 private void CheckDiffuseMapTexture(MaterialMapperContext materialMapperContext)
73 var diffuseTexturePropertyName = materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.DiffuseTexture);
74 var texture = LoadTexture(materialMapperContext, TextureType.Diffuse, materialMapperContext.Material.GetTextureValue(diffuseTexturePropertyName));
75 ApplyDiffuseMapTexture(materialMapperContext, TextureType.Diffuse, texture);
78 private void ApplyDiffuseMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType, Texture texture)
80 materialMapperContext.VirtualMaterial.SetProperty(
"_MainTex", texture);
83 private void CheckGlossinessValue(MaterialMapperContext materialMapperContext)
85 var value = materialMapperContext.Material.GetGenericPropertyValueMultiplied(GenericMaterialProperty.Glossiness, materialMapperContext.Material.GetGenericFloatValue(GenericMaterialProperty.Glossiness));
86 materialMapperContext.VirtualMaterial.SetProperty(
"_Glossiness", value);
87 materialMapperContext.VirtualMaterial.SetProperty(
"_GlossMapScale", value);
90 private void CheckMetallicValue(MaterialMapperContext materialMapperContext)
92 var value = materialMapperContext.Material.GetGenericPropertyValueMultiplied(GenericMaterialProperty.Metallic, materialMapperContext.Material.GetGenericFloatValue(GenericMaterialProperty.Metallic));
93 materialMapperContext.VirtualMaterial.SetProperty(
"_Metallic", value);
96 private void CheckEmissionMapTexture(MaterialMapperContext materialMapperContext)
98 var emissionTexturePropertyName = materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.EmissionTexture);
99 var texture = LoadTexture(materialMapperContext, TextureType.Emission, materialMapperContext.Material.GetTextureValue(emissionTexturePropertyName));
100 ApplyEmissionMapTexture(materialMapperContext, TextureType.Emission, texture);
103 private void ApplyEmissionMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType, Texture texture)
105 materialMapperContext.VirtualMaterial.SetProperty(
"_EmissionMap", texture);
108 materialMapperContext.VirtualMaterial.EnableKeyword(
"_EMISSION");
109 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
113 materialMapperContext.VirtualMaterial.DisableKeyword(
"_EMISSION");
114 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack;
118 private void CheckNormalMapTexture(MaterialMapperContext materialMapperContext)
120 var normalMapTexturePropertyName = materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.NormalTexture);
121 var texture = LoadTexture(materialMapperContext, TextureType.NormalMap, materialMapperContext.Material.GetTextureValue(normalMapTexturePropertyName));
122 ApplyNormalMapTexture(materialMapperContext, TextureType.NormalMap, texture);
125 private void ApplyNormalMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType, Texture texture)
127 materialMapperContext.VirtualMaterial.SetProperty(
"_BumpMap", texture);
130 materialMapperContext.VirtualMaterial.EnableKeyword(
"_NORMALMAP");
134 materialMapperContext.VirtualMaterial.DisableKeyword(
"_NORMALMAP");
138 private void CheckSpecularTexture(MaterialMapperContext materialMapperContext)
140 var specularTexturePropertyName = materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.SpecularTexture);
141 var texture = LoadTexture(materialMapperContext, TextureType.Specular, materialMapperContext.Material.GetTextureValue(specularTexturePropertyName));
142 ApplySpecGlossMapTexture(materialMapperContext, TextureType.Specular, texture);
145 private void ApplySpecGlossMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType, Texture texture)
147 materialMapperContext.VirtualMaterial.SetProperty(
"_SpecGlossMap", texture);
150 materialMapperContext.VirtualMaterial.EnableKeyword(
"_SPECGLOSSMAP");
154 materialMapperContext.VirtualMaterial.DisableKeyword(
"_SPECGLOSSMAP");
158 private void CheckOcclusionMapTexture(MaterialMapperContext materialMapperContext)
160 var occlusionMapTextureName = materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.OcclusionTexture);
161 var texture = LoadTexture(materialMapperContext, TextureType.Occlusion, materialMapperContext.Material.GetTextureValue(occlusionMapTextureName));
162 ApplyOcclusionMapTexture(materialMapperContext, TextureType.Occlusion, texture);
165 private void ApplyOcclusionMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType, Texture texture)
167 materialMapperContext.VirtualMaterial.SetProperty(
"_OcclusionMap", texture);
170 materialMapperContext.VirtualMaterial.EnableKeyword(
"_OCCLUSIONMAP");
174 materialMapperContext.VirtualMaterial.DisableKeyword(
"_OCCLUSIONMAP");
178 private void CheckParallaxMapTexture(MaterialMapperContext materialMapperContext)
180 var parallaxMapTextureName = materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.ParallaxMap);
181 var texture = LoadTexture(materialMapperContext, TextureType.Parallax, materialMapperContext.Material.GetTextureValue(parallaxMapTextureName));
182 ApplyParallaxMapTexture(materialMapperContext, TextureType.Parallax, texture);
185 private void ApplyParallaxMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType, Texture texture)
187 materialMapperContext.VirtualMaterial.SetProperty(
"_ParallaxMap", texture);
190 materialMapperContext.VirtualMaterial.EnableKeyword(
"_PARALLAXMAP");
194 materialMapperContext.VirtualMaterial.DisableKeyword(
"_PARALLAXMAP");
198 private void CheckMetallicGlossMapTexture(MaterialMapperContext materialMapperContext)
200 var metallicGlossMapTextureName = materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.MetallicGlossMap);
201 var texture = LoadTexture(materialMapperContext, TextureType.Metalness, materialMapperContext.Material.GetTextureValue(metallicGlossMapTextureName));
202 ApplyMetallicGlossMapTexture(materialMapperContext, TextureType.Metalness, texture);
205 private void ApplyMetallicGlossMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType, Texture texture)
207 materialMapperContext.VirtualMaterial.SetProperty(
"_MetallicGlossMap", texture);
210 materialMapperContext.VirtualMaterial.EnableKeyword(
"_METALLICGLOSSMAP");
214 materialMapperContext.VirtualMaterial.DisableKeyword(
"_METALLICGLOSSMAP");
218 private void CheckEmissionColor(MaterialMapperContext materialMapperContext)
220 var value = materialMapperContext.Material.GetGenericColorValue(GenericMaterialProperty.EmissionColor) * materialMapperContext.Material.GetGenericPropertyValueMultiplied(GenericMaterialProperty.EmissionColor, 1f);
221 materialMapperContext.VirtualMaterial.SetProperty(
"_EmissionColor", value);
222 if (value !=
Color.black)
224 materialMapperContext.VirtualMaterial.EnableKeyword(
"_EMISSION");
225 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
229 materialMapperContext.VirtualMaterial.DisableKeyword(
"_EMISSION");
230 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack;
234 private void CheckDiffuseColor(MaterialMapperContext materialMapperContext)
236 var value = materialMapperContext.Material.GetGenericColorValue(GenericMaterialProperty.DiffuseColor) * materialMapperContext.Material.GetGenericPropertyValueMultiplied(GenericMaterialProperty.DiffuseColor, 1f);
237 value.a *= materialMapperContext.Material.GetGenericFloatValue(GenericMaterialProperty.AlphaValue);
238 if (!materialMapperContext.VirtualMaterial.HasAlpha && value.a < 1f)
240 materialMapperContext.VirtualMaterial.HasAlpha =
true;
242 materialMapperContext.VirtualMaterial.SetProperty(
"_Color", value);
Represents a Material Mapper that converts TriLib Materials into Unity Standard Materials.
override Material LoadingMaterial
inheritdoc />
override Material MaterialPreset
override Material SpecularMaterialPreset
override Material SpecularAlphaMaterialPreset2
override bool IsCompatible(MaterialMapperContext materialMapperContext)
inheritdoc />
override Material AlphaMaterialPreset2
override Material SpecularAlphaMaterialPreset
override void Map(MaterialMapperContext materialMapperContext)
override Material AlphaMaterialPreset
Represents the TriLib project settings provider. You can override this behavior to store the settings...
static bool GetBool(string key)