Skip to content

Commit 99bddd5

Browse files
Merge pull request #3100 from secondlife/v-2570
#2570: Fix BoM texture interference on PBR materials. Also fix PBR copy/paste (#3099)
2 parents 97324f4 + b635675 commit 99bddd5

File tree

6 files changed

+65
-38
lines changed

6 files changed

+65
-38
lines changed

indra/newview/llfetchedgltfmaterial.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ void LLFetchedGLTFMaterial::updateTextureTracking()
221221
}
222222
}
223223

224+
void LLFetchedGLTFMaterial::clearFetchedTextures()
225+
{
226+
mBaseColorTexture = nullptr;
227+
mNormalTexture = nullptr;
228+
mMetallicRoughnessTexture = nullptr;
229+
mEmissiveTexture = nullptr;
230+
}
231+
224232
void LLFetchedGLTFMaterial::materialBegin()
225233
{
226234
llassert(!mFetching);

indra/newview/llfetchedgltfmaterial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class LLFetchedGLTFMaterial: public LLGLTFMaterial
6767
LLPointer<LLViewerFetchedTexture> mNormalTexture;
6868
LLPointer<LLViewerFetchedTexture> mMetallicRoughnessTexture;
6969
LLPointer<LLViewerFetchedTexture> mEmissiveTexture;
70+
void clearFetchedTextures();
7071

7172
std::set<LLTextureEntry*> mTextureEntires;
7273

indra/newview/llgltfmateriallist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool))
409409
{
410410
callback_holder = std::make_shared<CallbackHolder>(done_callback);
411411
}
412-
while (!sModifyQueue.empty() || !sApplyQueue.empty())
412+
while (!sModifyQueue.empty() || !sApplyQueue.empty() || !sUpdates.isEmpty())
413413
{
414414
flushUpdatesOnce(callback_holder);
415415
}

indra/newview/llpanelface.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,8 +4404,7 @@ void LLPanelFace::onPasteTexture(LLViewerObject* objectp, S32 te)
44044404
if (te_data["te"].has("pbr"))
44054405
{
44064406
objectp->setRenderMaterialID(te, te_data["te"]["pbr"].asUUID(), false /*managing our own update*/);
4407-
tep->setGLTFRenderMaterial(nullptr);
4408-
tep->setGLTFMaterialOverride(nullptr);
4407+
objectp->setTEGLTFMaterialOverride(te, nullptr);
44094408

44104409
LLSD override_data;
44114410
override_data["object_id"] = objectp->getID();
@@ -4426,8 +4425,7 @@ void LLPanelFace::onPasteTexture(LLViewerObject* objectp, S32 te)
44264425
else
44274426
{
44284427
objectp->setRenderMaterialID(te, LLUUID::null, false /*send in bulk later*/ );
4429-
tep->setGLTFRenderMaterial(nullptr);
4430-
tep->setGLTFMaterialOverride(nullptr);
4428+
objectp->setTEGLTFMaterialOverride(te, nullptr);
44314429

44324430
// blank out most override data on the server
44334431
LLGLTFMaterialList::queueApply(objectp, te, LLUUID::null);

indra/newview/llviewerobject.cpp

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5075,11 +5075,10 @@ void LLViewerObject::setNumTEs(const U8 num_tes)
50755075
if (base_material && override_material)
50765076
{
50775077
tep->setGLTFMaterialOverride(new LLGLTFMaterial(*override_material));
5078-
5079-
LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial();
5080-
*render_material = *base_material;
5081-
render_material->applyOverride(*override_material);
5082-
tep->setGLTFRenderMaterial(render_material);
5078+
}
5079+
if (base_material)
5080+
{
5081+
initRenderMaterial(i);
50835082
}
50845083
}
50855084
}
@@ -5254,6 +5253,9 @@ void LLViewerObject::updateTEMaterialTextures(U8 te)
52545253
});
52555254
}
52565255
getTE(te)->setGLTFMaterial(mat);
5256+
initRenderMaterial(te);
5257+
mat = (LLFetchedGLTFMaterial*) getTE(te)->getGLTFRenderMaterial();
5258+
llassert(mat == nullptr || dynamic_cast<LLFetchedGLTFMaterial*>(getTE(te)->getGLTFRenderMaterial()) != nullptr);
52575259
}
52585260
else if (mat_id.isNull() && mat != nullptr)
52595261
{
@@ -5643,6 +5645,42 @@ S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMateri
56435645
return retval;
56445646
}
56455647

5648+
// Set render material if there are overrides or if the base material is has a
5649+
// baked texture. Otherwise, set it to null.
5650+
// If you are setting the material override and not sending an update message,
5651+
// you should probably call this function.
5652+
S32 LLViewerObject::initRenderMaterial(U8 te)
5653+
{
5654+
LL_PROFILE_ZONE_SCOPED;
5655+
5656+
LLTextureEntry* tep = getTE(te);
5657+
if (!tep) { return 0; }
5658+
const LLFetchedGLTFMaterial* base_material = static_cast<LLFetchedGLTFMaterial*>(tep->getGLTFMaterial());
5659+
llassert(base_material);
5660+
if (!base_material) { return 0; }
5661+
const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride();
5662+
LLFetchedGLTFMaterial* render_material = nullptr;
5663+
bool need_render_material = override_material;
5664+
if (!need_render_material)
5665+
{
5666+
for (const LLUUID& texture_id : base_material->mTextureId)
5667+
{
5668+
if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(texture_id))
5669+
{
5670+
need_render_material = true;
5671+
break;
5672+
}
5673+
}
5674+
}
5675+
if (need_render_material)
5676+
{
5677+
render_material = new LLFetchedGLTFMaterial(*base_material);
5678+
if (override_material) { render_material->applyOverride(*override_material); }
5679+
render_material->clearFetchedTextures();
5680+
}
5681+
return tep->setGLTFRenderMaterial(render_material);
5682+
}
5683+
56465684
S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* override_mat)
56475685
{
56485686
LL_PROFILE_ZONE_SCOPED;
@@ -5676,22 +5714,13 @@ S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* override_ma
56765714

56775715
if (retval)
56785716
{
5717+
retval = initRenderMaterial(te) | retval;
56795718
if (override_mat)
56805719
{
5681-
LLFetchedGLTFMaterial* render_mat = new LLFetchedGLTFMaterial(*src_mat);
5682-
render_mat->applyOverride(*override_mat);
5683-
tep->setGLTFRenderMaterial(render_mat);
5684-
retval = TEM_CHANGE_TEXTURE;
5685-
56865720
for (LLGLTFMaterial::local_tex_map_t::value_type &val : override_mat->mTrackingIdToLocalTexture)
56875721
{
56885722
LLLocalBitmapMgr::getInstance()->associateGLTFMaterial(val.first, override_mat);
56895723
}
5690-
5691-
}
5692-
else if (tep->setGLTFRenderMaterial(nullptr))
5693-
{
5694-
retval = TEM_CHANGE_TEXTURE;
56955724
}
56965725
}
56975726

@@ -7561,25 +7590,15 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
75617590
// the overrides have not changed due to being only texture
75627591
// transforms. Re-apply the overrides to the render material here,
75637592
// if present.
7564-
const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride();
7565-
if (override_material)
7593+
// Also, sometimes, the material has baked textures, which requires
7594+
// a copy unique to this object.
7595+
// Currently, we do not deduplicate render materials.
7596+
new_material->onMaterialComplete([obj_id = getID(), te]()
75667597
{
7567-
new_material->onMaterialComplete([obj_id = getID(), te]()
7568-
{
7569-
LLViewerObject* obj = gObjectList.findObject(obj_id);
7570-
if (!obj) { return; }
7571-
LLTextureEntry* tep = obj->getTE(te);
7572-
if (!tep) { return; }
7573-
const LLGLTFMaterial* new_material = tep->getGLTFMaterial();
7574-
if (!new_material) { return; }
7575-
const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride();
7576-
if (!override_material) { return; }
7577-
LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial();
7578-
*render_material = *new_material;
7579-
render_material->applyOverride(*override_material);
7580-
tep->setGLTFRenderMaterial(render_material);
7581-
});
7582-
}
7598+
LLViewerObject* obj = gObjectList.findObject(obj_id);
7599+
if (!obj) { return; }
7600+
obj->initRenderMaterial(te);
7601+
});
75837602
}
75847603
}
75857604

indra/newview/llviewerobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ class LLViewerObject
389389
/*virtual*/ S32 setTEGlow(const U8 te, const F32 glow);
390390
/*virtual*/ S32 setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
391391
/*virtual*/ S32 setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams);
392+
S32 initRenderMaterial(const U8 te);
392393
virtual S32 setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* mat);
393394

394395
// Used by Materials update functions to properly kick off rebuilds

0 commit comments

Comments
 (0)