diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.h b/code/AssetLib/glTF2/glTF2AssetWriter.h index ce58717f3..355fdfeed 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.h +++ b/code/AssetLib/glTF2/glTF2AssetWriter.h @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * glTF Extensions Support: * KHR_materials_pbrSpecularGlossiness: full * KHR_materials_unlit: full + * KHR_materials_sheen: full */ #ifndef GLTF2ASSETWRITER_H_INC #define GLTF2ASSETWRITER_H_INC diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 786a1e7b8..3d1e6d263 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -417,6 +417,25 @@ namespace glTF2 { exts.AddMember("KHR_materials_unlit", unlit, w.mAl); } + if (m.materialSheen.isPresent) { + Value materialSheen(rapidjson::Type::kObjectType); + + MaterialSheen &sheen = m.materialSheen.value; + + WriteVec(materialSheen, sheen.sheenColorFactor, "sheenColorFactor", defaultSheenFactor, w.mAl); + + if (sheen.sheenRoughnessFactor != 0.f) { + WriteFloat(materialSheen, sheen.sheenRoughnessFactor, "sheenRoughnessFactor", w.mAl); + } + + WriteTex(materialSheen, sheen.sheenColorTexture, "sheenColorTexture", w.mAl); + WriteTex(materialSheen, sheen.sheenRoughnessTexture, "sheenRoughnessTexture", w.mAl); + + if (!materialSheen.ObjectEmpty()) { + exts.AddMember("KHR_materials_sheen", materialSheen, w.mAl); + } + } + if (!exts.ObjectEmpty()) { obj.AddMember("extensions", exts, w.mAl); } @@ -808,6 +827,10 @@ namespace glTF2 { if (this->mAsset.extensionsUsed.KHR_materials_unlit) { exts.PushBack(StringRef("KHR_materials_unlit"), mAl); } + + if (this->mAsset.extensionsUsed.KHR_materials_sheen) { + exts.PushBack(StringRef("KHR_materials_sheen"), mAl); + } } if (!exts.Empty()) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 637808877..65309a66a 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -714,6 +714,22 @@ void glTF2Exporter::ExportMaterials() mAsset->extensionsUsed.KHR_materials_unlit = true; m->unlit = true; } + + bool hasMaterialSheen = false; + mat->Get(AI_MATKEY_GLTF_MATERIAL_SHEEN, hasMaterialSheen); + + if (hasMaterialSheen) { + mAsset->extensionsUsed.KHR_materials_sheen = true; + + MaterialSheen sheen; + + GetMatColor(mat, sheen.sheenColorFactor, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_FACTOR); + mat->Get(AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_FACTOR, sheen.sheenRoughnessFactor); + GetMatTex(mat, sheen.sheenColorTexture, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_TEXTURE); + GetMatTex(mat, sheen.sheenRoughnessTexture, AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_TEXTURE); + + m->materialSheen = Nullable(sheen); + } } }