Start managing and importing gltf2 pbr materials

pull/1423/head
Daniel Hritzkiv 2017-08-27 23:47:54 -04:00
parent 67eb3b0608
commit b42d785afe
No known key found for this signature in database
GPG Key ID: D1D19875679D5CBF
2 changed files with 44 additions and 15 deletions

View File

@ -671,11 +671,18 @@ namespace glTF2
inline void SetData(uint8_t* data, size_t length, Asset& r); inline void SetData(uint8_t* data, size_t length, Asset& r);
}; };
//! Holds a material property that can be a texture or a color struct ColorProperty
struct TexProperty {
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; Ref<Texture> texture;
vec4 color; ColorProperty color;
}; };
//! The material appearance of a primitive. //! The material appearance of a primitive.
@ -694,16 +701,27 @@ namespace glTF2
Technique_CONSTANT Technique_CONSTANT
}; };
TexProperty ambient; //PBR metallic roughness properties
TexProperty diffuse; ColorProperty baseColor;
TexProperty specular; Ref<Texture> baseColorTexture;
TexProperty emission; Ref<Texture> metallicRoughnessTexture;
Ref<Texture> normal; 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 doubleSided;
bool transparent;
float transparency; //fallback material properties (compatible with non-pbr defintions)
float shininess; FallbackTexProperty diffuse;
FallbackTexProperty emissive;
FallbackTexProperty specular;
Ref<Texture> normal;
Technique technique; Technique technique;

View File

@ -725,18 +725,29 @@ inline void Material::Read(Value& material, Asset& r)
SetDefaults(); SetDefaults();
if (Value* values = FindObject(material, "values")) { 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, "transparency", transparency);
ReadMember(*values, "shininess", shininess);
} }
if (Value* values = FindObject(material, "pbrMetallicRoughness")) { 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, "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); ReadMember(material, "doubleSided", doubleSided);
if (Value* extensions = FindObject(material, "extensions")) { if (Value* extensions = FindObject(material, "extensions")) {