diff options
| author | Dave Parks <davep@lindenlab.com> | 2022-10-19 14:41:17 -0500 |
|---|---|---|
| committer | Dave Parks <davep@lindenlab.com> | 2022-10-19 14:41:17 -0500 |
| commit | de4c018499ddaebbe466fb5a8938554a2d4a3b19 (patch) | |
| tree | c2571311bb27190bc2ef9ff03c071169748ef7a2 /indra/llprimitive/llgltfmaterial.cpp | |
| parent | d0c2c862efe2ce684b48092465cc753b3ab64da9 (diff) | |
SL-18105 Hook up render pipe directly to LLTextureEntry::mGLTFMaterial and add LLViewerFetchedTextures to LLFetchedGLTFMaterial. Lower reflection probe resolution to 128x128 per side.
Diffstat (limited to 'indra/llprimitive/llgltfmaterial.cpp')
| -rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 187 |
1 files changed, 171 insertions, 16 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index 951b768678..19081cd76f 100644 --- a/indra/llprimitive/llgltfmaterial.cpp +++ b/indra/llprimitive/llgltfmaterial.cpp @@ -28,12 +28,44 @@ #include "llgltfmaterial.h" -#include "tiny_gltf.h" +#include "tinygltf/tiny_gltf.h" + +LLGLTFMaterial::LLGLTFMaterial(const LLGLTFMaterial& rhs) +{ + *this = rhs; +} + +LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs) +{ + //have to do a manual operator= because of LLRefCount + mBaseColorId = rhs.mBaseColorId; + mNormalId = rhs.mNormalId; + mMetallicRoughnessId = rhs.mMetallicRoughnessId; + mEmissiveId = rhs.mEmissiveId; + + mBaseColor = rhs.mBaseColor; + mEmissiveColor = rhs.mEmissiveColor; + + mMetallicFactor = rhs.mMetallicFactor; + mRoughnessFactor = rhs.mRoughnessFactor; + mAlphaCutoff = rhs.mAlphaCutoff; + + mDoubleSided = rhs.mDoubleSided; + mAlphaMode = rhs.mAlphaMode; + + for (S32 i = 0; i < 3; ++i) + { + mTextureTransform[i] = rhs.mTextureTransform[i]; + } + + return *this; +} bool LLGLTFMaterial::fromJSON(const std::string& json, std::string& warn_msg, std::string& error_msg) { +#if 1 tinygltf::TinyGLTF gltf; - + tinygltf::Model model_in; if (gltf.LoadASCIIFromString(&model_in, &error_msg, &warn_msg, json.c_str(), json.length(), "")) @@ -45,12 +77,13 @@ bool LLGLTFMaterial::fromJSON(const std::string& json, std::string& warn_msg, st return true; } - +#endif return false; } std::string LLGLTFMaterial::asJSON(bool prettyprint) const { +#if 1 tinygltf::TinyGLTF gltf; tinygltf::Model model_out; @@ -61,6 +94,9 @@ std::string LLGLTFMaterial::asJSON(bool prettyprint) const gltf.WriteGltfSceneToStream(&model_out, str, prettyprint, false); return str.str(); +#else + return ""; +#endif } void LLGLTFMaterial::setFromModel(const tinygltf::Model& model, S32 mat_index) @@ -130,7 +166,7 @@ void LLGLTFMaterial::setFromModel(const tinygltf::Model& model, S32 mat_index) void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const { - if (model.materials.size() < mat_index+1) + if (model.materials.size() < mat_index + 1) { model.materials.resize(mat_index + 1); } @@ -143,7 +179,7 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const U32 idx = model.images.size(); model.images.resize(idx + 1); model.textures.resize(idx + 1); - + material_out.pbrMetallicRoughness.baseColorTexture.index = idx; model.textures[idx].source = idx; model.images[idx].uri = mBaseColorId.asString(); @@ -160,7 +196,7 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const model.textures[idx].source = idx; model.images[idx].uri = mNormalId.asString(); } - + // set metallic-roughness texture if (mMetallicRoughnessId.notNull()) { @@ -187,7 +223,7 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const material_out.alphaMode = getAlphaMode(); material_out.alphaCutoff = mAlphaCutoff; - + mBaseColor.write(material_out.pbrMetallicRoughness.baseColorFactor); mEmissiveColor.write(material_out.emissiveFactor); @@ -195,11 +231,130 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const material_out.pbrMetallicRoughness.roughnessFactor = mRoughnessFactor; material_out.doubleSided = mDoubleSided; + + model.asset.version = "2.0"; +} + + +void LLGLTFMaterial::setBaseColorId(const LLUUID& id) +{ + mBaseColorId = id; +} + +void LLGLTFMaterial::setNormalId(const LLUUID& id) +{ + mNormalId = id; +} + +void LLGLTFMaterial::setMetallicRoughnessId(const LLUUID& id) +{ + mMetallicRoughnessId = id; +} + +void LLGLTFMaterial::setEmissiveId(const LLUUID& id) +{ + mEmissiveId = id; +} + +void LLGLTFMaterial::setBaseColorFactor(const LLColor3& baseColor, F32 transparency) +{ + mBaseColor.set(baseColor, transparency); + mBaseColor.clamp(); +} + +void LLGLTFMaterial::setAlphaCutoff(F32 cutoff) +{ + mAlphaCutoff = llclamp(cutoff, 0.f, 1.f); +} + +void LLGLTFMaterial::setEmissiveColorFactor(const LLColor3& emissiveColor) +{ + mEmissiveColor = emissiveColor; + mEmissiveColor.clamp(); +} + +void LLGLTFMaterial::setMetallicFactor(F32 metallic) +{ + mMetallicFactor = llclamp(metallic, 0.f, 1.f); +} + +void LLGLTFMaterial::setRoughnessFactor(F32 roughness) +{ + mRoughnessFactor = llclamp(roughness, 0.f, 1.f); +} + +void LLGLTFMaterial::setAlphaMode(S32 mode) +{ + mAlphaMode = (AlphaMode)llclamp(mode, (S32)ALPHA_MODE_OPAQUE, (S32)ALPHA_MODE_MASK); +} + +void LLGLTFMaterial::setDoubleSided(bool double_sided) +{ + // sure, no clamping will ever be needed for a bool, but include the + // setter for consistency with the clamping API + mDoubleSided = double_sided; +} + +// Default value accessors + +LLUUID LLGLTFMaterial::getDefaultBaseColorId() +{ + return LLUUID::null; +} + +LLUUID LLGLTFMaterial::getDefaultNormalId() +{ + return LLUUID::null; +} + +LLUUID LLGLTFMaterial::getDefaultEmissiveId() +{ + return LLUUID::null; +} + +LLUUID LLGLTFMaterial::getDefaultMetallicRoughnessId() +{ + return LLUUID::null; +} + +F32 LLGLTFMaterial::getDefaultAlphaCutoff() +{ + return 0.f; +} + +S32 LLGLTFMaterial::getDefaultAlphaMode() +{ + return (S32)ALPHA_MODE_OPAQUE; +} + +F32 LLGLTFMaterial::getDefaultMetallicFactor() +{ + return 0.f; +} + +F32 LLGLTFMaterial::getDefaultRoughnessFactor() +{ + return 0.f; +} + +LLColor4 LLGLTFMaterial::getDefaultBaseColor() +{ + return LLColor4::white; +} + +LLColor3 LLGLTFMaterial::getDefaultEmissiveColor() +{ + return LLColor3::black; +} + +bool LLGLTFMaterial::getDefaultDoubleSided() +{ + return false; } -void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model & model, S32 mat_index, LLGLTFMaterial const * base_material) const +void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model& model, S32 mat_index, LLGLTFMaterial const* base_material) const { - if (model.materials.size() < mat_index+1) + if (model.materials.size() < mat_index + 1) { model.materials.resize(mat_index + 1); } @@ -256,37 +411,37 @@ void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model & model, S32 mat_inde model.images[idx].uri = mEmissiveId.asString(); } - if(mAlphaMode != base_material->mAlphaMode) + if (mAlphaMode != base_material->mAlphaMode) { material_out.alphaMode = getAlphaMode(); } - if(mAlphaCutoff != base_material->mAlphaCutoff) + if (mAlphaCutoff != base_material->mAlphaCutoff) { material_out.alphaCutoff = mAlphaCutoff; } - if(mBaseColor != base_material->mBaseColor) + if (mBaseColor != base_material->mBaseColor) { mBaseColor.write(material_out.pbrMetallicRoughness.baseColorFactor); } - if(mEmissiveColor != base_material->mEmissiveColor) + if (mEmissiveColor != base_material->mEmissiveColor) { mEmissiveColor.write(material_out.emissiveFactor); } - if(mMetallicFactor != base_material->mMetallicFactor) + if (mMetallicFactor != base_material->mMetallicFactor) { material_out.pbrMetallicRoughness.metallicFactor = mMetallicFactor; } - if(mRoughnessFactor != base_material->mRoughnessFactor) + if (mRoughnessFactor != base_material->mRoughnessFactor) { material_out.pbrMetallicRoughness.roughnessFactor = mRoughnessFactor; } - if(mDoubleSided != base_material->mDoubleSided) + if (mDoubleSided != base_material->mDoubleSided) { material_out.doubleSided = mDoubleSided; } |
