13 [CreateAssetMenu(menuName =
"TriLib/Mappers/Material/Universal RP Material Mapper",
14 fileName =
"UniversalRPMaterialMapper")]
20 public override Material
MaterialPreset => Resources.Load<Material>(
"Materials/UniversalRP/TriLibUniversalRP");
23 Resources.Load<Material>(
"Materials/UniversalRP/TriLibUniversalRPAlphaCutout");
26 Resources.Load<Material>(
"Materials/UniversalRP/TriLibUniversalRPAlpha");
29 Resources.Load<Material>(
"Materials/UniversalRP/TriLibUniversalRPSpecular");
32 Resources.Load<Material>(
"Materials/UniversalRP/TriLibUniversalRPAlphaCutoutSpecular");
35 Resources.Load<Material>(
"Materials/UniversalRP/TriLibUniversalRPAlphaSpecular");
38 Resources.Load<Material>(
"Materials/UniversalRP/TriLibUniversalRPLoading");
41 public override bool IsCompatible(MaterialMapperContext materialMapperContext)
47 public override void Map(MaterialMapperContext materialMapperContext)
49 materialMapperContext.VirtualMaterial =
new VirtualMaterial();
51 CheckDiffuseColor(materialMapperContext);
52 CheckDiffuseMapTexture(materialMapperContext);
53 CheckNormalMapTexture(materialMapperContext);
54 CheckEmissionColor(materialMapperContext);
55 CheckEmissionMapTexture(materialMapperContext);
56 CheckOcclusionMapTexture(materialMapperContext);
57 CheckParallaxMapTexture(materialMapperContext);
59 if (materialMapperContext.Material.MaterialShadingSetup == MaterialShadingSetup.Specular)
61 CheckMetallicValue(materialMapperContext);
62 CheckMetallicGlossMapTexture(materialMapperContext);
63 CheckGlossinessValue(materialMapperContext);
64 CheckSpecularTexture(materialMapperContext);
68 CheckGlossinessValue(materialMapperContext);
69 CheckSpecularTexture(materialMapperContext);
70 CheckMetallicValue(materialMapperContext);
71 CheckMetallicGlossMapTexture(materialMapperContext);
74 BuildMaterial(materialMapperContext);
77 private void CheckDiffuseMapTexture(MaterialMapperContext materialMapperContext)
79 var diffuseTexturePropertyName =
80 materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.DiffuseTexture);
81 var texture = LoadTexture(materialMapperContext, TextureType.Diffuse,
82 materialMapperContext.Material.GetTextureValue(diffuseTexturePropertyName));
83 ApplyDiffuseMapTexture(materialMapperContext, TextureType.Diffuse, texture);
86 private void ApplyDiffuseMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType,
89 materialMapperContext.VirtualMaterial.SetProperty(
"_BaseMap", texture);
92 private void CheckGlossinessValue(MaterialMapperContext materialMapperContext)
94 var value = materialMapperContext.Material.GetGenericPropertyValueMultiplied(
95 GenericMaterialProperty.Glossiness,
96 materialMapperContext.Material.GetGenericFloatValue(GenericMaterialProperty.Glossiness));
97 materialMapperContext.VirtualMaterial.SetProperty(
"_Smoothness", value);
100 private void CheckMetallicValue(MaterialMapperContext materialMapperContext)
102 var value = materialMapperContext.Material.GetGenericFloatValue(GenericMaterialProperty.Metallic);
103 materialMapperContext.VirtualMaterial.SetProperty(
"_Metallic", value);
106 private void CheckEmissionMapTexture(MaterialMapperContext materialMapperContext)
108 var emissionTexturePropertyName =
109 materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.EmissionTexture);
110 var texture = LoadTexture(materialMapperContext, TextureType.Emission,
111 materialMapperContext.Material.GetTextureValue(emissionTexturePropertyName));
112 ApplyEmissionMapTexture(materialMapperContext, TextureType.Emission, texture);
115 private void ApplyEmissionMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType,
118 materialMapperContext.VirtualMaterial.SetProperty(
"_EmissionMap", texture);
121 materialMapperContext.VirtualMaterial.EnableKeyword(
"_EMISSION");
122 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags =
123 MaterialGlobalIlluminationFlags.RealtimeEmissive;
127 materialMapperContext.VirtualMaterial.DisableKeyword(
"_EMISSION");
128 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags =
129 MaterialGlobalIlluminationFlags.EmissiveIsBlack;
133 private void CheckNormalMapTexture(MaterialMapperContext materialMapperContext)
135 var normalMapTexturePropertyName =
136 materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.NormalTexture);
137 var texture = LoadTexture(materialMapperContext, TextureType.NormalMap,
138 materialMapperContext.Material.GetTextureValue(normalMapTexturePropertyName));
139 ApplyNormalMapTexture(materialMapperContext, TextureType.NormalMap, texture);
142 private void ApplyNormalMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType,
145 materialMapperContext.VirtualMaterial.SetProperty(
"_BumpMap", texture);
148 materialMapperContext.VirtualMaterial.EnableKeyword(
"_NORMALMAP");
149 materialMapperContext.VirtualMaterial.SetProperty(
"_NormalScale",
150 materialMapperContext.Material.GetGenericPropertyValueMultiplied(
151 GenericMaterialProperty.NormalTexture, 1f));
155 materialMapperContext.VirtualMaterial.DisableKeyword(
"_NORMALMAP");
159 private void CheckSpecularTexture(MaterialMapperContext materialMapperContext)
161 var specularTexturePropertyName =
162 materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.SpecularTexture);
163 var texture = LoadTexture(materialMapperContext, TextureType.Specular,
164 materialMapperContext.Material.GetTextureValue(specularTexturePropertyName));
165 ApplySpecGlossMapTexture(materialMapperContext, TextureType.Specular, texture);
168 private void ApplySpecGlossMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType,
171 materialMapperContext.VirtualMaterial.SetProperty(
"_SpecGlossMap", texture);
173 materialMapperContext.VirtualMaterial.EnableKeyword(
"_METALLICSPECGLOSSMAP");
175 materialMapperContext.VirtualMaterial.DisableKeyword(
"_METALLICSPECGLOSSMAP");
178 private void CheckOcclusionMapTexture(MaterialMapperContext materialMapperContext)
180 var occlusionMapTextureName =
181 materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.OcclusionTexture);
182 var texture = LoadTexture(materialMapperContext, TextureType.Occlusion,
183 materialMapperContext.Material.GetTextureValue(occlusionMapTextureName));
184 ApplyOcclusionMapTexture(materialMapperContext, TextureType.Occlusion, texture);
187 private void ApplyOcclusionMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType,
190 materialMapperContext.VirtualMaterial.SetProperty(
"_OcclusionMap", texture);
192 materialMapperContext.VirtualMaterial.EnableKeyword(
"_OCCLUSIONMAP");
194 materialMapperContext.VirtualMaterial.DisableKeyword(
"_OCCLUSIONMAP");
197 private void CheckParallaxMapTexture(MaterialMapperContext materialMapperContext)
199 var parallaxMapTextureName =
200 materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.ParallaxMap);
201 var texture = LoadTexture(materialMapperContext, TextureType.Parallax,
202 materialMapperContext.Material.GetTextureValue(parallaxMapTextureName));
203 ApplyParallaxMapTexture(materialMapperContext, TextureType.Parallax, texture);
206 private void ApplyParallaxMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType,
209 materialMapperContext.VirtualMaterial.SetProperty(
"_ParallaxMap", texture);
211 materialMapperContext.VirtualMaterial.EnableKeyword(
"_PARALLAXMAP");
213 materialMapperContext.VirtualMaterial.DisableKeyword(
"_PARALLAXMAP");
216 private void CheckMetallicGlossMapTexture(MaterialMapperContext materialMapperContext)
218 var metallicGlossMapTextureName =
219 materialMapperContext.Material.GetGenericPropertyName(GenericMaterialProperty.MetallicGlossMap);
220 var texture = LoadTexture(materialMapperContext, TextureType.Metalness,
221 materialMapperContext.Material.GetTextureValue(metallicGlossMapTextureName));
222 ApplyMetallicGlossMapTexture(materialMapperContext, TextureType.Metalness, texture);
225 private void ApplyMetallicGlossMapTexture(MaterialMapperContext materialMapperContext, TextureType textureType,
228 materialMapperContext.VirtualMaterial.SetProperty(
"_MetallicGlossMap", texture);
230 materialMapperContext.VirtualMaterial.EnableKeyword(
"_METALLICGLOSSMAP");
232 materialMapperContext.VirtualMaterial.DisableKeyword(
"_METALLICGLOSSMAP");
235 private void CheckEmissionColor(MaterialMapperContext materialMapperContext)
237 var value = materialMapperContext.Material.GetGenericColorValue(GenericMaterialProperty.EmissionColor) *
238 materialMapperContext.Material.GetGenericPropertyValueMultiplied(
239 GenericMaterialProperty.EmissionColor, 1f);
240 materialMapperContext.VirtualMaterial.SetProperty(
"_EmissionColor", value);
241 if (value !=
Color.black)
243 materialMapperContext.VirtualMaterial.EnableKeyword(
"_EMISSION");
244 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags =
245 MaterialGlobalIlluminationFlags.RealtimeEmissive;
249 materialMapperContext.VirtualMaterial.DisableKeyword(
"_EMISSION");
250 materialMapperContext.VirtualMaterial.GlobalIlluminationFlags =
251 MaterialGlobalIlluminationFlags.EmissiveIsBlack;
255 private void CheckDiffuseColor(MaterialMapperContext materialMapperContext)
257 var value = materialMapperContext.Material.GetGenericColorValue(GenericMaterialProperty.DiffuseColor) *
258 materialMapperContext.Material.GetGenericPropertyValueMultiplied(
259 GenericMaterialProperty.DiffuseColor, 1f);
260 value.a *= materialMapperContext.Material.GetGenericFloatValue(GenericMaterialProperty.AlphaValue);
261 if (!materialMapperContext.VirtualMaterial.HasAlpha && value.a < 1f)
262 materialMapperContext.VirtualMaterial.HasAlpha =
true;
263 materialMapperContext.VirtualMaterial.SetProperty(
"_BaseColor", value);
Represents the TriLib project settings provider. You can override this behavior to store the settings...
static bool GetBool(string key)
Represents a Material Mapper that converts TriLib Materials into Unity UniversalRP Materials.
override bool IsCompatible(MaterialMapperContext materialMapperContext)
inheritdoc />
override Material AlphaMaterialPreset2
override Material LoadingMaterial
inheritdoc />
override Material MaterialPreset
override Material SpecularAlphaMaterialPreset
override void Map(MaterialMapperContext materialMapperContext)
override Material SpecularMaterialPreset
override Material SpecularAlphaMaterialPreset2
override Material AlphaMaterialPreset