SL-18105 Hook up TE override material to render pipe by way of render material.

master
Dave Parks 2022-10-19 17:23:54 -05:00
parent de4c018499
commit 8741c05cc1
10 changed files with 99 additions and 18 deletions

View File

@ -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
}

View File

@ -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);
};

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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.

View File

@ -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;

View File

@ -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;