summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2022-10-19 17:23:54 -0500
committerDave Parks <davep@lindenlab.com>2022-10-19 17:23:54 -0500
commit8741c05cc10d3f39f272bb4739e7313309539d07 (patch)
tree871d2340a7e22cce1504948a79a703811a084d5a
parentde4c018499ddaebbe466fb5a8938554a2d4a3b19 (diff)
SL-18105 Hook up TE override material to render pipe by way of render material.
-rw-r--r--indra/llprimitive/llgltfmaterial.cpp25
-rw-r--r--indra/llprimitive/llgltfmaterial.h3
-rw-r--r--indra/llprimitive/lltextureentry.cpp19
-rw-r--r--indra/llprimitive/lltextureentry.h13
-rw-r--r--indra/newview/llface.cpp6
-rw-r--r--indra/newview/llgltfmateriallist.cpp6
-rw-r--r--indra/newview/llviewerobject.cpp32
-rw-r--r--indra/newview/llviewerobject.h1
-rw-r--r--indra/newview/llvovolume.cpp10
-rw-r--r--indra/newview/pipeline.cpp2
10 files changed, 99 insertions, 18 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp
index 19081cd76f..b9ef2de61a 100644
--- a/indra/llprimitive/llgltfmaterial.cpp
+++ b/indra/llprimitive/llgltfmaterial.cpp
@@ -446,3 +446,28 @@ void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model& model, S32 mat_index
material_out.doubleSided = mDoubleSided;
}
}
+
+void LLGLTFMaterial::applyOverride(const LLGLTFMaterial& override_mat)
+{
+ if (override_mat.mBaseColorId != getDefaultBaseColorId())
+ {
+ mBaseColorId = override_mat.mBaseColorId;
+ }
+
+ if (override_mat.mNormalId != getDefaultNormalId())
+ {
+ mNormalId = override_mat.mNormalId;
+ }
+
+ if (override_mat.mMetallicRoughnessId != getDefaultMetallicRoughnessId())
+ {
+ mMetallicRoughnessId = override_mat.mMetallicRoughnessId;
+ }
+
+ if (override_mat.mEmissiveId != getDefaultEmissiveId())
+ {
+ mEmissiveId = override_mat.mEmissiveId;
+ }
+
+ //TODO -- implement non texture parameters
+}
diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h
index 9c82f08805..32695d92f4 100644
--- a/indra/llprimitive/llgltfmaterial.h
+++ b/indra/llprimitive/llgltfmaterial.h
@@ -174,5 +174,8 @@ public:
// calculate the fields in this material that differ from a base material and write them out to a given tinygltf::Model
void writeOverridesToModel(tinygltf::Model& model, S32 mat_index, LLGLTFMaterial const* base_material) const;
+
+ void applyOverride(const LLGLTFMaterial& override_mat);
+
};
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp
index 284dfc15f4..e185404ada 100644
--- a/indra/llprimitive/lltextureentry.cpp
+++ b/indra/llprimitive/lltextureentry.cpp
@@ -491,6 +491,25 @@ S32 LLTextureEntry::setBumpShiny(U8 bump_shiny)
return TEM_CHANGE_NONE;
}
+void LLTextureEntry::setGLTFMaterial(LLGLTFMaterial* material)
+{
+ mGLTFMaterial = material;
+ if (mGLTFMaterial == nullptr)
+ {
+ setGLTFRenderMaterial(nullptr);
+ }
+}
+
+S32 LLTextureEntry::setGLTFRenderMaterial(LLGLTFMaterial* mat)
+{
+ if (mGLTFRenderMaterial != mat)
+ {
+ mGLTFRenderMaterial = mat;
+ return TEM_CHANGE_TEXTURE;
+ }
+ return TEM_CHANGE_NONE;
+}
+
S32 LLTextureEntry::setMediaFlags(U8 media_flags)
{
media_flags &= TEM_MEDIA_MASK;
diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h
index bb74d258fd..2c932a10df 100644
--- a/indra/llprimitive/lltextureentry.h
+++ b/indra/llprimitive/lltextureentry.h
@@ -163,8 +163,6 @@ public:
const LLMaterialID& getMaterialID() const { return mMaterialID; };
const LLMaterialPtr getMaterialParams() const { return mMaterial; };
- LLGLTFMaterial* getGLTFMaterial() const { return mGLTFMaterial; }
-
// *NOTE: it is possible for hasMedia() to return true, but getMediaData() to return NULL.
// CONVERSELY, it is also possible for hasMedia() to return false, but getMediaData()
// to NOT return NULL.
@@ -197,16 +195,17 @@ public:
enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 };
// GLTF asset
- void setGLTFMaterial(LLGLTFMaterial* material) { mGLTFMaterial = material; }
- LLGLTFMaterial* getGLTFMaterial() { return mGLTFMaterial; }
+ void setGLTFMaterial(LLGLTFMaterial* material);
+ LLGLTFMaterial* getGLTFMaterial() const { return mGLTFMaterial; }
// GLTF override
LLGLTFMaterial* getGLTFMaterialOverride() { return mGLTFMaterialOverrides; }
void setGLTFMaterialOverride(LLGLTFMaterial* mat) { mGLTFMaterialOverrides = mat; }
- // GLTF render
- LLGLTFMaterial* getGLTFRenderMaterial() { return mGLTFRenderMaterial; }
- void setGLTFRenderMaterial(LLGLTFMaterial* mat) { mGLTFRenderMaterial = mat; }
+ // GLTF render material
+ // nuanced behavior here -- if there is no render material, fall back to getGLTFMaterial, but ONLY for the getter, not the setter
+ LLGLTFMaterial* getGLTFRenderMaterial() const { return mGLTFRenderMaterial.notNull() ? mGLTFRenderMaterial : getGLTFMaterial(); }
+ S32 setGLTFRenderMaterial(LLGLTFMaterial* mat);
public:
F32 mScaleS; // S, T offset
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 4ae8335ca7..23b56aa579 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -1334,9 +1334,9 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
LLColor4U color = tep->getColor();
- if (tep->getGLTFMaterial())
+ if (tep->getGLTFRenderMaterial())
{
- color = tep->getGLTFMaterial()->mBaseColor;
+ color = tep->getGLTFRenderMaterial()->mBaseColor;
}
if (rebuild_color)
@@ -1599,7 +1599,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
scalea.load3(scale.mV);
LLMaterial* mat = tep->getMaterialParams().get();
- LLGLTFMaterial* gltf_mat = tep->getGLTFMaterial();
+ LLGLTFMaterial* gltf_mat = tep->getGLTFRenderMaterial();
bool do_bump = bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1);
diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp
index 9c04ef4c38..86f4faa9d0 100644
--- a/indra/newview/llgltfmateriallist.cpp
+++ b/indra/newview/llgltfmateriallist.cpp
@@ -36,6 +36,7 @@
#include "llviewercontrol.h"
#include "llviewergenericmessage.h"
#include "llviewerobjectlist.h"
+#include "pipeline.h"
#include "tinygltf/tiny_gltf.h"
#include <strstream>
@@ -86,7 +87,10 @@ namespace
if(obj)
{
- obj->getTE(side)->setGLTFMaterialOverride(override_data);
+ if (obj->setTEGLTFMaterialOverride(side, override_data))
+ {
+ gPipeline.markTextured(obj->mDrawable);
+ }
}
LL_DEBUGS() << "successfully parsed override: " << override_data->asJSON() << LL_ENDL;
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index ccc1259c25..4923771a31 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -4920,7 +4920,7 @@ void LLViewerObject::updateTEMaterialTextures(U8 te)
mTESpecularMaps[te] = LLViewerTextureManager::getFetchedTexture(spec_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_ALM, LLViewerTexture::LOD_TEXTURE);
}
- LLFetchedGLTFMaterial* mat = (LLFetchedGLTFMaterial*) getTE(te)->getGLTFMaterial();
+ LLFetchedGLTFMaterial* mat = (LLFetchedGLTFMaterial*) getTE(te)->getGLTFRenderMaterial();
LLUUID mat_id = getRenderMaterialID(te);
if (mat == nullptr && mat_id.notNull())
{
@@ -5319,6 +5319,36 @@ S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMateri
return retval;
}
+S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* override_mat)
+{
+ S32 retval = TEM_CHANGE_NONE;
+
+ LLTextureEntry* tep = getTE(te);
+ if (!tep)
+ {
+ LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+ return retval;
+ }
+
+ LLFetchedGLTFMaterial* src_mat = (LLFetchedGLTFMaterial*) tep->getGLTFMaterial();
+
+ tep->setGLTFMaterialOverride(override_mat);
+
+ if (override_mat && src_mat)
+ {
+ LLFetchedGLTFMaterial* render_mat = new LLFetchedGLTFMaterial(*src_mat);
+ render_mat->applyOverride(*override_mat);
+ tep->setGLTFRenderMaterial(render_mat);
+ retval = TEM_CHANGE_TEXTURE;
+ }
+ else if (tep->setGLTFRenderMaterial(nullptr))
+ {
+ retval = TEM_CHANGE_TEXTURE;
+ }
+
+ return retval;
+}
+
void LLViewerObject::refreshMaterials()
{
setChanged(TEXTURE);
diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h
index 5d72f7f3c3..bd70532ab7 100644
--- a/indra/newview/llviewerobject.h
+++ b/indra/newview/llviewerobject.h
@@ -356,6 +356,7 @@ public:
/*virtual*/ S32 setTEGlow(const U8 te, const F32 glow);
/*virtual*/ S32 setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
/*virtual*/ S32 setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams);
+ S32 setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* mat);
// Used by Materials update functions to properly kick off rebuilds
// of VBs etc when materials updates require changes.
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index c1c80d5adc..127abde19e 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -5223,7 +5223,7 @@ bool can_batch_texture(LLFace* facep)
return false;
}
- if (facep->getTextureEntry()->getGLTFMaterial() != nullptr)
+ if (facep->getTextureEntry()->getGLTFRenderMaterial() != nullptr)
{ // PBR materials break indexed texture batching
return false;
}
@@ -5390,7 +5390,7 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep,
LLUUID mat_id;
- auto* gltf_mat = (LLFetchedGLTFMaterial*) facep->getTextureEntry()->getGLTFMaterial();
+ auto* gltf_mat = (LLFetchedGLTFMaterial*) facep->getTextureEntry()->getGLTFRenderMaterial();
if (gltf_mat != nullptr)
{
mat_id = gltf_mat->getHash(); // TODO: cache this hash
@@ -5873,7 +5873,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
bool is_pbr = false;
#endif
#else
- LLGLTFMaterial *gltf_mat = facep->getTextureEntry()->getGLTFMaterial();
+ LLGLTFMaterial *gltf_mat = facep->getTextureEntry()->getGLTFRenderMaterial();
bool is_pbr = gltf_mat != nullptr;
#endif
@@ -6011,7 +6011,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
if (gPipeline.canUseWindLightShadersOnObjects()
&& LLPipeline::sRenderBump)
{
- LLGLTFMaterial* gltf_mat = te->getGLTFMaterial();
+ LLGLTFMaterial* gltf_mat = te->getGLTFRenderMaterial();
if (LLPipeline::sRenderDeferred &&
(gltf_mat != nullptr || (te->getMaterialParams().notNull() && !te->getMaterialID().isNull())))
@@ -6716,7 +6716,7 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
BOOL is_alpha = (facep->getPoolType() == LLDrawPool::POOL_ALPHA) ? TRUE : FALSE;
- LLGLTFMaterial* gltf_mat = te->getGLTFMaterial();
+ LLGLTFMaterial* gltf_mat = te->getGLTFRenderMaterial();
LLMaterial* mat = nullptr;
bool can_be_shiny = false;
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index cb54cec165..b6d9e5fd36 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -1617,7 +1617,7 @@ U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* ima
}
LLMaterial* mat = te->getMaterialParams().get();
- LLGLTFMaterial* gltf_mat = te->getGLTFMaterial();
+ LLGLTFMaterial* gltf_mat = te->getGLTFRenderMaterial();
bool color_alpha = te->getColor().mV[3] < 0.999f;
bool alpha = color_alpha;