Start removing materials common, and adding pbrSpecularGlossiness
parent
7615a97cd3
commit
863458cd4a
|
@ -44,7 +44,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* glTF Extensions Support:
|
* glTF Extensions Support:
|
||||||
* KHR_binary_glTF: full
|
* KHR_binary_glTF: full
|
||||||
* KHR_materials_common: full
|
|
||||||
*/
|
*/
|
||||||
#ifndef GLTF2ASSET_H_INC
|
#ifndef GLTF2ASSET_H_INC
|
||||||
#define GLTF2ASSET_H_INC
|
#define GLTF2ASSET_H_INC
|
||||||
|
@ -697,19 +696,6 @@ namespace glTF2
|
||||||
//! The material appearance of a primitive.
|
//! The material appearance of a primitive.
|
||||||
struct Material : public Object
|
struct Material : public Object
|
||||||
{
|
{
|
||||||
//Ref<Sampler> source; //!< The ID of the technique.
|
|
||||||
//std::gltf_unordered_map<std::string, std::string> values; //!< A dictionary object of parameter values.
|
|
||||||
|
|
||||||
//! Techniques defined by KHR_materials_common
|
|
||||||
enum Technique
|
|
||||||
{
|
|
||||||
Technique_undefined = 0,
|
|
||||||
Technique_BLINN,
|
|
||||||
Technique_PHONG,
|
|
||||||
Technique_LAMBERT,
|
|
||||||
Technique_CONSTANT
|
|
||||||
};
|
|
||||||
|
|
||||||
//PBR metallic roughness properties
|
//PBR metallic roughness properties
|
||||||
vec4 baseColorFactor;
|
vec4 baseColorFactor;
|
||||||
TextureInfo baseColorTexture;
|
TextureInfo baseColorTexture;
|
||||||
|
@ -726,13 +712,12 @@ namespace glTF2
|
||||||
float alphaCutoff;
|
float alphaCutoff;
|
||||||
bool doubleSided;
|
bool doubleSided;
|
||||||
|
|
||||||
//fallback material properties (compatible with non-pbr defintions)
|
//extension: KHR_materials_pbrSpecularGlossiness
|
||||||
/*FallbackTexProperty diffuse;
|
vec4 diffuseFactor;
|
||||||
FallbackTexProperty emission;
|
vec3 specularFactor;
|
||||||
FallbackTexProperty specular;
|
float glossinessFactor;
|
||||||
Ref<Texture> normal;*/
|
TextureInfo diffuseTexture;
|
||||||
|
TextureInfo specularGlossinessTexture;
|
||||||
Technique technique;
|
|
||||||
|
|
||||||
Material() { SetDefaults(); }
|
Material() { SetDefaults(); }
|
||||||
void Read(Value& obj, Asset& r);
|
void Read(Value& obj, Asset& r);
|
||||||
|
@ -943,35 +928,6 @@ namespace glTF2
|
||||||
void Read(Value& obj, Asset& r);
|
void Read(Value& obj, Asset& r);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//! A light (from KHR_materials_common extension)
|
|
||||||
struct Light : public Object
|
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
Type_undefined,
|
|
||||||
Type_ambient,
|
|
||||||
Type_directional,
|
|
||||||
Type_point,
|
|
||||||
Type_spot
|
|
||||||
};
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
vec4 color;
|
|
||||||
float distance;
|
|
||||||
float constantAttenuation;
|
|
||||||
float linearAttenuation;
|
|
||||||
float quadraticAttenuation;
|
|
||||||
float falloffAngle;
|
|
||||||
float falloffExponent;
|
|
||||||
|
|
||||||
Light() {}
|
|
||||||
void Read(Value& obj, Asset& r);
|
|
||||||
|
|
||||||
void SetDefaults();
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Animation : public Object
|
struct Animation : public Object
|
||||||
{
|
{
|
||||||
struct AnimSampler {
|
struct AnimSampler {
|
||||||
|
@ -1152,7 +1108,7 @@ namespace glTF2
|
||||||
struct Extensions
|
struct Extensions
|
||||||
{
|
{
|
||||||
bool KHR_binary_glTF;
|
bool KHR_binary_glTF;
|
||||||
bool KHR_materials_common;
|
bool KHR_materials_pbrSpecularGlossiness;
|
||||||
|
|
||||||
} extensionsUsed;
|
} extensionsUsed;
|
||||||
|
|
||||||
|
@ -1170,16 +1126,11 @@ namespace glTF2
|
||||||
LazyDict<Material> materials;
|
LazyDict<Material> materials;
|
||||||
LazyDict<Mesh> meshes;
|
LazyDict<Mesh> meshes;
|
||||||
LazyDict<Node> nodes;
|
LazyDict<Node> nodes;
|
||||||
//LazyDict<Program> programs;
|
|
||||||
LazyDict<Sampler> samplers;
|
LazyDict<Sampler> samplers;
|
||||||
LazyDict<Scene> scenes;
|
LazyDict<Scene> scenes;
|
||||||
//LazyDict<Shader> shaders;
|
|
||||||
LazyDict<Skin> skins;
|
LazyDict<Skin> skins;
|
||||||
//LazyDict<Technique> techniques;
|
|
||||||
LazyDict<Texture> textures;
|
LazyDict<Texture> textures;
|
||||||
|
|
||||||
LazyDict<Light> lights; // KHR_materials_common ext
|
|
||||||
|
|
||||||
Ref<Scene> scene;
|
Ref<Scene> scene;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -1195,14 +1146,10 @@ namespace glTF2
|
||||||
, materials (*this, "materials")
|
, materials (*this, "materials")
|
||||||
, meshes (*this, "meshes")
|
, meshes (*this, "meshes")
|
||||||
, nodes (*this, "nodes")
|
, nodes (*this, "nodes")
|
||||||
//, programs (*this, "programs")
|
|
||||||
, samplers (*this, "samplers")
|
, samplers (*this, "samplers")
|
||||||
, scenes (*this, "scenes")
|
, scenes (*this, "scenes")
|
||||||
//, shaders (*this, "shaders")
|
, skins (*this, "skins")
|
||||||
, skins (*this, "skins")
|
|
||||||
//, techniques (*this, "techniques")
|
|
||||||
, textures (*this, "textures")
|
, textures (*this, "textures")
|
||||||
, lights (*this, "lights", "KHR_materials_common")
|
|
||||||
{
|
{
|
||||||
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
|
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
|
||||||
}
|
}
|
||||||
|
|
|
@ -757,12 +757,12 @@ inline void Material::Read(Value& material, Asset& r)
|
||||||
{
|
{
|
||||||
SetDefaults();
|
SetDefaults();
|
||||||
|
|
||||||
if (Value* values = FindObject(material, "pbrMetallicRoughness")) {
|
if (Value* pbrMetallicRoughness = FindObject(material, "pbrMetallicRoughness")) {
|
||||||
ReadMember(*values, "baseColorFactor", this->baseColorFactor);
|
ReadMember(*pbrMetallicRoughness, "baseColorFactor", this->baseColorFactor);
|
||||||
ReadTextureProperty(r, *values, "baseColorTexture", this->baseColorTexture);
|
ReadTextureProperty(r, *pbrMetallicRoughness, "baseColorTexture", this->baseColorTexture);
|
||||||
ReadTextureProperty(r, *values, "metallicRoughnessTexture", this->metallicRoughnessTexture);
|
ReadTextureProperty(r, *pbrMetallicRoughness, "metallicRoughnessTexture", this->metallicRoughnessTexture);
|
||||||
ReadMember(*values, "metallicFactor", this->metallicFactor);
|
ReadMember(*pbrMetallicRoughness, "metallicFactor", this->metallicFactor);
|
||||||
ReadMember(*values, "roughnessFactor", this->roughnessFactor);
|
ReadMember(*pbrMetallicRoughness, "roughnessFactor", this->roughnessFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadTextureProperty(r, material, "normalTexture", this->normalTexture);
|
ReadTextureProperty(r, material, "normalTexture", this->normalTexture);
|
||||||
|
@ -774,30 +774,17 @@ inline void Material::Read(Value& material, Asset& r)
|
||||||
ReadMember(material, "alphaMode", this->alphaMode);
|
ReadMember(material, "alphaMode", this->alphaMode);
|
||||||
ReadMember(material, "alphaCutoff", this->alphaCutoff);
|
ReadMember(material, "alphaCutoff", this->alphaCutoff);
|
||||||
|
|
||||||
/* if (Value* extensions = FindObject(material, "extensions")) {
|
if (Value* extensions = FindObject(material, "extensions")) {
|
||||||
if (r.extensionsUsed.KHR_materials_common) {
|
if (r.extensionsUsed.KHR_materials_pbrSpecularGlossiness) {
|
||||||
if (Value* ext = FindObject(*extensions, "KHR_materials_common")) {
|
if (Value* pbrSpecularGlossiness = FindObject(*extensions, "KHR_materials_pbrSpecularGlossiness")) {
|
||||||
if (Value* tnq = FindString(*ext, "technique")) {
|
ReadMember(*pbrSpecularGlossiness, "diffuseFactor", this->diffuseFactor);
|
||||||
const char* t = tnq->GetString();
|
ReadTextureProperty(r, *pbrSpecularGlossiness, "diffuseTexture", this->diffuseTexture);
|
||||||
if (strcmp(t, "BLINN") == 0) technique = Technique_BLINN;
|
ReadTextureProperty(r, *pbrSpecularGlossiness, "specularGlossinessTexture", this->specularGlossinessTexture);
|
||||||
else if (strcmp(t, "PHONG") == 0) technique = Technique_PHONG;
|
ReadMember(*pbrSpecularGlossiness, "specularFactor", this->specularFactor);
|
||||||
else if (strcmp(t, "LAMBERT") == 0) technique = Technique_LAMBERT;
|
ReadMember(*pbrSpecularGlossiness, "glossinessFactor", this->glossinessFactor);
|
||||||
else if (strcmp(t, "CONSTANT") == 0) technique = Technique_CONSTANT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Value* values = FindObject(*ext, "values")) {
|
|
||||||
ReadTextureProperty(r, *values, "ambient", this->ambient);
|
|
||||||
ReadTextureProperty(r, *values, "diffuse", this->diffuse);
|
|
||||||
ReadTextureProperty(r, *values, "specular", this->specular);
|
|
||||||
|
|
||||||
ReadMember(*values, "doubleSided", doubleSided);
|
|
||||||
ReadMember(*values, "transparent", transparent);
|
|
||||||
ReadMember(*values, "transparency", transparency);
|
|
||||||
ReadMember(*values, "shininess", shininess);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -820,7 +807,10 @@ inline void Material::SetDefaults()
|
||||||
alphaCutoff = 0.5;
|
alphaCutoff = 0.5;
|
||||||
doubleSided = false;
|
doubleSided = false;
|
||||||
|
|
||||||
technique = Technique_undefined;
|
//pbrSpecularGlossiness properties
|
||||||
|
SetVector(diffuseFactor, 1, 1, 1, 1);
|
||||||
|
SetVector(specularFactor, 1, 1, 1);
|
||||||
|
glossinessFactor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -1083,20 +1073,6 @@ inline void Node::Read(Value& obj, Asset& r)
|
||||||
if (this->camera)
|
if (this->camera)
|
||||||
this->camera->id = this->id;
|
this->camera->id = this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO load "skeletons", "skin", "jointName"
|
|
||||||
|
|
||||||
/*if (Value* extensions = FindObject(obj, "extensions")) {
|
|
||||||
if (r.extensionsUsed.KHR_materials_common) {
|
|
||||||
|
|
||||||
if (Value* ext = FindObject(*extensions, "KHR_materials_common")) {
|
|
||||||
if (Value* light = FindUInt(*ext, "light")) {
|
|
||||||
this->light = r.lights.Retrieve(light->GetUint());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Scene::Read(Value& obj, Asset& r)
|
inline void Scene::Read(Value& obj, Asset& r)
|
||||||
|
@ -1293,7 +1269,7 @@ inline void Asset::ReadExtensionsUsed(Document& doc)
|
||||||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||||
|
|
||||||
CHECK_EXT(KHR_binary_glTF);
|
CHECK_EXT(KHR_binary_glTF);
|
||||||
CHECK_EXT(KHR_materials_common);
|
CHECK_EXT(KHR_materials_pbrSpecularGlossiness);
|
||||||
|
|
||||||
#undef CHECK_EXT
|
#undef CHECK_EXT
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* glTF Extensions Support:
|
* glTF Extensions Support:
|
||||||
* KHR_binary_glTF: full
|
* KHR_binary_glTF: full
|
||||||
* KHR_materials_common: full
|
* KHR_materials_pbrSpecularGlossiness: full
|
||||||
*/
|
*/
|
||||||
#ifndef GLTF2ASSETWRITER_H_INC
|
#ifndef GLTF2ASSETWRITER_H_INC
|
||||||
#define GLTF2ASSETWRITER_H_INC
|
#define GLTF2ASSETWRITER_H_INC
|
||||||
|
|
|
@ -327,23 +327,35 @@ namespace glTF2 {
|
||||||
obj.AddMember("doubleSided", m.doubleSided, w.mAl);
|
obj.AddMember("doubleSided", m.doubleSided, w.mAl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Value v;
|
Value pbrSpecularGlossiness;
|
||||||
v.SetObject();
|
pbrSpecularGlossiness.SetObject();
|
||||||
{
|
{
|
||||||
if (m.transparent && !m.diffuse.texture) {
|
//pbrSpecularGlossiness
|
||||||
m.diffuse.color[3] = m.transparency;
|
|
||||||
|
vec4 defaultDiffuseFactor = {1, 1, 1, 1};
|
||||||
|
WriteVec(pbrSpecularGlossiness, m.diffuseFactor, "diffuseFactor", defaultDiffuseFactor, w.mAl);
|
||||||
|
|
||||||
|
vec3 defaultSpecularFactor = {1, 1, 1};
|
||||||
|
WriteVec(pbrSpecularGlossiness, m.specularFactor, "specularFactor", defaultSpecularFactor, w.mAl);
|
||||||
|
|
||||||
|
if (m.glossinessFactor != 1) {
|
||||||
|
WriteFloat(obj, m.glossinessFactor, "glossinessFactor", w.mAl);
|
||||||
}
|
}
|
||||||
WriteVecOrTex(v, m.ambient, m.ambient.texture ? "ambientTexture" : "ambientFactor", w.mAl);
|
|
||||||
WriteVecOrTex(v, m.diffuse, m.diffuse.texture ? "diffuseTexture" : "diffuseFactor", w.mAl);
|
WriteTex(obj, m.diffuseTexture, "diffuseTexture", w.mAl);
|
||||||
WriteVecOrTex(v, m.specular, m.specular.texture ? "specularTexture" : "specularFactor", w.mAl);
|
WriteTex(obj, m.specularGlossinessTexture, "specularGlossinessTexture", w.mAl);
|
||||||
WriteVecOrTex(v, m.emission, m.emission.texture ? "emissionTexture" : "emissionFactor", w.mAl);
|
|
||||||
v.AddMember("shininessFactor", m.shininess, w.mAl);
|
|
||||||
}
|
}
|
||||||
v.AddMember("type", "commonPhong", w.mAl);
|
|
||||||
Value ext;
|
Value ext;
|
||||||
ext.SetObject();
|
ext.SetObject();
|
||||||
ext.AddMember("KHR_materials_common", v, w.mAl);
|
|
||||||
obj.AddMember("extensions", ext, w.mAl);*/
|
if (!pbrSpecularGlossiness.ObjectEmpty()) {
|
||||||
|
ext.AddMember("KHR_materials_pbrSpecularGlossiness", pbrSpecularGlossiness, w.mAl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ext.ObjectEmpty()) {
|
||||||
|
obj.AddMember("extensions", ext, w.mAl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -714,11 +726,11 @@ namespace glTF2 {
|
||||||
Value exts;
|
Value exts;
|
||||||
exts.SetArray();
|
exts.SetArray();
|
||||||
{
|
{
|
||||||
if (false)
|
//if (false)
|
||||||
exts.PushBack(StringRef("KHR_binary_glTF"), mAl);
|
// exts.PushBack(StringRef("KHR_binary_glTF"), mAl);
|
||||||
|
|
||||||
// This is used to export common materials with GLTF 2.
|
// This is used to export common materials with GLTF 2.
|
||||||
//exts.PushBack(StringRef("KHR_materials_common"), mAl);
|
//exts.PushBack(StringRef("KHR_materials_pbrSpecularGlossiness"), mAl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exts.Empty())
|
if (!exts.Empty())
|
||||||
|
|
|
@ -237,6 +237,13 @@ void glTF2Importer::ImportMaterials(glTF2::Asset& r)
|
||||||
aimat->AddProperty(&mat.doubleSided, 1, AI_MATKEY_TWOSIDED);
|
aimat->AddProperty(&mat.doubleSided, 1, AI_MATKEY_TWOSIDED);
|
||||||
aimat->AddProperty(&mat.alphaMode, 1, "$mat.gltf.alphaMode");
|
aimat->AddProperty(&mat.alphaMode, 1, "$mat.gltf.alphaMode");
|
||||||
aimat->AddProperty(&mat.alphaCutoff, 1, "$mat.gltf.alphaCutoff");
|
aimat->AddProperty(&mat.alphaCutoff, 1, "$mat.gltf.alphaCutoff");
|
||||||
|
|
||||||
|
//pbrSpecularGlossiness
|
||||||
|
SetMaterialColorProperty(r, mat.diffuseFactor, aimat, "$clr.diffuse", 0, 1);
|
||||||
|
SetMaterialColorProperty(r, mat.specularFactor, aimat, "$clr.specular", 0, 1);
|
||||||
|
aimat->AddProperty(&mat.glossinessFactor, 1, "$mat.gltf.glossinessFactor");
|
||||||
|
SetMaterialTextureProperty(embeddedTexIdxs, r, mat.diffuseTexture, aimat, aiTextureType_DIFFUSE, 1);
|
||||||
|
SetMaterialTextureProperty(embeddedTexIdxs, r, mat.specularGlossinessTexture, aimat, aiTextureType_UNKNOWN, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue