Start managing and importing gltf2 pbr materials
parent
67eb3b0608
commit
b42d785afe
|
@ -671,11 +671,18 @@ namespace glTF2
|
|||
inline void SetData(uint8_t* data, size_t length, Asset& r);
|
||||
};
|
||||
|
||||
//! Holds a material property that can be a texture or a color
|
||||
struct TexProperty
|
||||
struct ColorProperty
|
||||
{
|
||||
union {
|
||||
vec4, vec3
|
||||
} color;
|
||||
}
|
||||
|
||||
//! Holds a material property that can be a texture or a color (fallback for glTF 1)
|
||||
struct FallbackTexProperty
|
||||
{
|
||||
Ref<Texture> texture;
|
||||
vec4 color;
|
||||
ColorProperty color;
|
||||
};
|
||||
|
||||
//! The material appearance of a primitive.
|
||||
|
@ -694,16 +701,27 @@ namespace glTF2
|
|||
Technique_CONSTANT
|
||||
};
|
||||
|
||||
TexProperty ambient;
|
||||
TexProperty diffuse;
|
||||
TexProperty specular;
|
||||
TexProperty emission;
|
||||
Ref<Texture> normal;
|
||||
//PBR metallic roughness properties
|
||||
ColorProperty baseColor;
|
||||
Ref<Texture> baseColorTexture;
|
||||
Ref<Texture> metallicRoughnessTexture;
|
||||
float metallicFactor;
|
||||
float roughnessFactor;
|
||||
|
||||
//other basic material properties
|
||||
Ref<Texture> normalTexture;
|
||||
Ref<Texture> occlusionTexture;
|
||||
Ref<Texture> emissiveTexture;
|
||||
ColorProperty emissiveFactor;
|
||||
std::string alphaMode;
|
||||
float alphaCutoff;
|
||||
bool doubleSided;
|
||||
bool transparent;
|
||||
float transparency;
|
||||
float shininess;
|
||||
|
||||
//fallback material properties (compatible with non-pbr defintions)
|
||||
FallbackTexProperty diffuse;
|
||||
FallbackTexProperty emissive;
|
||||
FallbackTexProperty specular;
|
||||
Ref<Texture> normal;
|
||||
|
||||
Technique technique;
|
||||
|
||||
|
|
|
@ -725,18 +725,29 @@ inline void Material::Read(Value& material, Asset& r)
|
|||
SetDefaults();
|
||||
|
||||
if (Value* values = FindObject(material, "values")) {
|
||||
ReadMaterialProperty(r, *values, "ambient", this->ambient);
|
||||
ReadMaterialProperty(r, *values, "diffuse", this->diffuse);
|
||||
ReadMaterialProperty(r, *values, "specular", this->specular);
|
||||
|
||||
|
||||
ReadMember(*values, "transparency", transparency);
|
||||
ReadMember(*values, "shininess", shininess);
|
||||
}
|
||||
|
||||
if (Value* values = FindObject(material, "pbrMetallicRoughness")) {
|
||||
//pbr
|
||||
ReadMaterialProperty(r, *values, "baseColorFactor", this->baseColor);
|
||||
ReadMaterialProperty(r, *values, "baseColorTexture", this->baseColorTexture);
|
||||
|
||||
//non-pbr fallback
|
||||
ReadMaterialProperty(r, *values, "baseColorFactor", this->diffuse);
|
||||
ReadMaterialProperty(r, *values, "baseColorTexture", this->diffuse);
|
||||
|
||||
ReadMember(*values, "metallicFactor", metallicFactor);
|
||||
}
|
||||
|
||||
ReadMaterialProperty(r, *values, "normalTexture", this->normalTexture);
|
||||
ReadMaterialProperty(r, *values, "normalTexture", this->normal);
|
||||
ReadMaterialProperty(r, *values, "occlusionTexture", this->occlusionTexture);
|
||||
ReadMaterialProperty(r, *values, "emissiveTexture", this->emissiveTexture);
|
||||
ReadMember(*values, "metallicFactor", emissiveFactor);
|
||||
|
||||
ReadMember(material, "doubleSided", doubleSided);
|
||||
|
||||
if (Value* extensions = FindObject(material, "extensions")) {
|
||||
|
|
Loading…
Reference in New Issue