parent
1a5823700f
commit
03cfa04ee4
|
@ -135,8 +135,7 @@ namespace glTF2
|
||||||
// Vec/matrix types, as raw float arrays
|
// Vec/matrix types, as raw float arrays
|
||||||
typedef float (vec3)[3];
|
typedef float (vec3)[3];
|
||||||
typedef float (vec4)[4];
|
typedef float (vec4)[4];
|
||||||
typedef float (mat4)[16];
|
typedef float (mat4)[16];
|
||||||
|
|
||||||
|
|
||||||
namespace Util
|
namespace Util
|
||||||
{
|
{
|
||||||
|
@ -670,7 +669,12 @@ namespace glTF2
|
||||||
inline uint8_t* StealData();
|
inline uint8_t* StealData();
|
||||||
|
|
||||||
inline void SetData(uint8_t* data, size_t length, Asset& r);
|
inline void SetData(uint8_t* data, size_t length, Asset& r);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const vec4 defaultBaseColor = {1, 1, 1, 1};
|
||||||
|
const vec3 defaultEmissiveFactor = {0, 0, 0};
|
||||||
|
const vec4 defaultDiffuseFactor = {1, 1, 1, 1};
|
||||||
|
const vec3 defaultSpecularFactor = {1, 1, 1};
|
||||||
|
|
||||||
struct TextureInfo
|
struct TextureInfo
|
||||||
{
|
{
|
||||||
|
|
|
@ -803,28 +803,28 @@ inline void Material::Read(Value& material, Asset& r)
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void SetVector(vec4& v, float x, float y, float z, float w)
|
void SetVector(vec4& v, const float(&in)[4])
|
||||||
{ v[0] = x; v[1] = y; v[2] = z; v[3] = w; }
|
{ v[0] = in[0]; v[1] = in[1]; v[2] = in[2]; v[3] = in[3]; }
|
||||||
|
|
||||||
void SetVector(vec3& v, float x, float y, float z)
|
void SetVector(vec3& v, const float(&in)[3])
|
||||||
{ v[0] = x; v[1] = y; v[2] = z; }
|
{ v[0] = in[0]; v[1] = in[1]; v[2] = in[2]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Material::SetDefaults()
|
inline void Material::SetDefaults()
|
||||||
{
|
{
|
||||||
//pbr materials
|
//pbr materials
|
||||||
SetVector(pbrMetallicRoughness.baseColorFactor, 1, 1, 1, 1);
|
SetVector(pbrMetallicRoughness.baseColorFactor, defaultBaseColor);
|
||||||
pbrMetallicRoughness.metallicFactor = 1.0;
|
pbrMetallicRoughness.metallicFactor = 1.0;
|
||||||
pbrMetallicRoughness.roughnessFactor = 1.0;
|
pbrMetallicRoughness.roughnessFactor = 1.0;
|
||||||
|
|
||||||
SetVector(emissiveFactor, 0, 0, 0);
|
SetVector(emissiveFactor, defaultEmissiveFactor);
|
||||||
alphaMode = "OPAQUE";
|
alphaMode = "OPAQUE";
|
||||||
alphaCutoff = 0.5;
|
alphaCutoff = 0.5;
|
||||||
doubleSided = false;
|
doubleSided = false;
|
||||||
|
|
||||||
//pbrSpecularGlossiness properties
|
//pbrSpecularGlossiness properties
|
||||||
SetVector(pbrSpecularGlossiness.diffuseFactor, 1, 1, 1, 1);
|
SetVector(pbrSpecularGlossiness.diffuseFactor, defaultDiffuseFactor);
|
||||||
SetVector(pbrSpecularGlossiness.specularFactor, 1, 1, 1);
|
SetVector(pbrSpecularGlossiness.specularFactor, defaultSpecularFactor);
|
||||||
pbrSpecularGlossiness.glossinessFactor = 1.0;
|
pbrSpecularGlossiness.glossinessFactor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -268,7 +268,7 @@ namespace glTF2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
inline void WriteVec(Value& obj, float(&prop)[N], const char* propName, float(&defaultVal)[N], MemoryPoolAllocator<>& al)
|
inline void WriteVec(Value& obj, float(&prop)[N], const char* propName, const float(&defaultVal)[N], MemoryPoolAllocator<>& al)
|
||||||
{
|
{
|
||||||
if (!std::equal(std::begin(prop), std::end(prop), std::begin(defaultVal))) {
|
if (!std::equal(std::begin(prop), std::end(prop), std::begin(defaultVal))) {
|
||||||
WriteVec(obj, prop, propName, al);
|
WriteVec(obj, prop, propName, al);
|
||||||
|
@ -289,10 +289,7 @@ namespace glTF2 {
|
||||||
{
|
{
|
||||||
WriteTex(pbrMetallicRoughness, m.pbrMetallicRoughness.baseColorTexture, "baseColorTexture", w.mAl);
|
WriteTex(pbrMetallicRoughness, m.pbrMetallicRoughness.baseColorTexture, "baseColorTexture", w.mAl);
|
||||||
WriteTex(pbrMetallicRoughness, m.pbrMetallicRoughness.metallicRoughnessTexture, "metallicRoughnessTexture", w.mAl);
|
WriteTex(pbrMetallicRoughness, m.pbrMetallicRoughness.metallicRoughnessTexture, "metallicRoughnessTexture", w.mAl);
|
||||||
|
WriteVec(pbrMetallicRoughness, m.pbrMetallicRoughness.baseColorFactor, "baseColorFactor", defaultBaseColor, w.mAl);
|
||||||
//@TODO: define this as a constant?
|
|
||||||
vec4 defaultEmissiveFactor = {1, 1, 1, 1};
|
|
||||||
WriteVec(pbrMetallicRoughness, m.pbrMetallicRoughness.baseColorFactor, "baseColorFactor", defaultEmissiveFactor, w.mAl);
|
|
||||||
|
|
||||||
if (m.pbrMetallicRoughness.metallicFactor != 1) {
|
if (m.pbrMetallicRoughness.metallicFactor != 1) {
|
||||||
WriteFloat(pbrMetallicRoughness, m.pbrMetallicRoughness.metallicFactor, "metallicFactor", w.mAl);
|
WriteFloat(pbrMetallicRoughness, m.pbrMetallicRoughness.metallicFactor, "metallicFactor", w.mAl);
|
||||||
|
@ -310,9 +307,6 @@ namespace glTF2 {
|
||||||
WriteTex(obj, m.normalTexture, "normalTexture", w.mAl);
|
WriteTex(obj, m.normalTexture, "normalTexture", w.mAl);
|
||||||
WriteTex(obj, m.emissiveTexture, "emissiveTexture", w.mAl);
|
WriteTex(obj, m.emissiveTexture, "emissiveTexture", w.mAl);
|
||||||
WriteTex(obj, m.occlusionTexture, "occlusionTexture", w.mAl);
|
WriteTex(obj, m.occlusionTexture, "occlusionTexture", w.mAl);
|
||||||
|
|
||||||
//@TODO: define this as a constant?
|
|
||||||
vec3 defaultEmissiveFactor = {0, 0, 0};
|
|
||||||
WriteVec(obj, m.emissiveFactor, "emissiveFactor", defaultEmissiveFactor, w.mAl);
|
WriteVec(obj, m.emissiveFactor, "emissiveFactor", defaultEmissiveFactor, w.mAl);
|
||||||
|
|
||||||
if (m.alphaCutoff != 0.5) {
|
if (m.alphaCutoff != 0.5) {
|
||||||
|
@ -335,11 +329,7 @@ namespace glTF2 {
|
||||||
pbrSpecularGlossiness.SetObject();
|
pbrSpecularGlossiness.SetObject();
|
||||||
{
|
{
|
||||||
//pbrSpecularGlossiness
|
//pbrSpecularGlossiness
|
||||||
|
|
||||||
vec4 defaultDiffuseFactor = {1, 1, 1, 1};
|
|
||||||
WriteVec(pbrSpecularGlossiness, m.pbrSpecularGlossiness.diffuseFactor, "diffuseFactor", defaultDiffuseFactor, w.mAl);
|
WriteVec(pbrSpecularGlossiness, m.pbrSpecularGlossiness.diffuseFactor, "diffuseFactor", defaultDiffuseFactor, w.mAl);
|
||||||
|
|
||||||
vec3 defaultSpecularFactor = {1, 1, 1};
|
|
||||||
WriteVec(pbrSpecularGlossiness, m.pbrSpecularGlossiness.specularFactor, "specularFactor", defaultSpecularFactor, w.mAl);
|
WriteVec(pbrSpecularGlossiness, m.pbrSpecularGlossiness.specularFactor, "specularFactor", defaultSpecularFactor, w.mAl);
|
||||||
|
|
||||||
if (m.pbrSpecularGlossiness.glossinessFactor != 1) {
|
if (m.pbrSpecularGlossiness.glossinessFactor != 1) {
|
||||||
|
|
Loading…
Reference in New Issue