-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefaultMaterialGenerator.cs
More file actions
41 lines (33 loc) · 1.55 KB
/
DefaultMaterialGenerator.cs
File metadata and controls
41 lines (33 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using GLTFast;
using GLTFast.Materials;
using GLTFast.Schema;
using System;
using UnityEngine;
using Material = UnityEngine.Material;
namespace DCL.GLTFast.Wrappers
{
/// <summary>
/// With this class we can override the material generation from GLTFast,
/// in this case we are using the ShaderGraphMaterialGenerator that comes from GLTFast
/// </summary>
internal class DefaultMaterialGenerator : ShaderGraphMaterialGenerator
{
private const float CUSTOM_EMISSIVE_FACTOR = 5f;
public override Material GenerateMaterial(MaterialBase gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
{
Material generatedMaterial = base.GenerateMaterial(gltfMaterial, gltf, pointsSupport);
SetMaterialName(generatedMaterial, gltfMaterial);
if (gltfMaterial.Emissive != Color.black) { generatedMaterial.SetColor(MaterialProperty.EmissiveFactor, gltfMaterial.Emissive * CUSTOM_EMISSIVE_FACTOR); }
return generatedMaterial;
// This step is important if we want to keep the functionality of skin and hair colouring
void SetMaterialName(Material material, MaterialBase materialBase)
{
material.name = "material";
if (materialBase.name.Contains("skin", StringComparison.InvariantCultureIgnoreCase))
material.name += "_skin";
if (materialBase.name.Contains("hair", StringComparison.InvariantCultureIgnoreCase))
material.name += "_hair";
}
}
}
}