From 66a01ba4c581d79227b0e67f5f75dc248fcaf7ab Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 28 Jan 2013 19:56:18 -0500 Subject: Basic normal mapping support. --- indra/newview/lldrawpoolbump.cpp | 1 + indra/newview/llspatialpartition.h | 2 +- indra/newview/llviewerobject.cpp | 5 ++-- indra/newview/llvovolume.cpp | 56 ++++++++++++++++++++++++-------------- indra/newview/llvovolume.h | 1 + 5 files changed, 42 insertions(+), 23 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index d613def1bd..fcc81dc723 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -677,6 +677,7 @@ BOOL LLDrawPoolBump::bindBumpMap(U8 bump_code, LLViewerTexture* texture, F32 vsi break; case BE_CUSTOM: bump = tex; + bump->addTextureStats(vsize); break; default: if( bump_code < LLStandardBumpmap::sStandardBumpmapCount ) diff --git a/indra/newview/llspatialpartition.h b/indra/newview/llspatialpartition.h index 2c4f6754ec..a71ca60d85 100644 --- a/indra/newview/llspatialpartition.h +++ b/indra/newview/llspatialpartition.h @@ -120,7 +120,7 @@ public: F32 mDistance; U32 mDrawMode; - LLMaterialID *mMaterialID; // If this is false, the following parameters are unused. + const LLMaterialID *mMaterialID; // If this is false, the following parameters are unused. LLPointer mSpecularMap; const LLMatrix4* mSpecularMapMatrix; LLPointer mNormalMap; diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index 5c684326e2..78c5b3ac53 100644 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -4110,8 +4110,8 @@ S32 LLViewerObject::setTENormalMapCore(const U8 te, const LLUUID& uuid, LLHost h { LL_INFOS("Materials") << "Maybe normal maps! " << uuid << LL_ENDL; S32 retval = 0; - if (uuid != getTE(te)->getMaterialParams()->getNormalID() || - uuid == LLUUID::null) + //if (uuid != getTE(te)->getMaterialParams()->getNormalID() || + //uuid == LLUUID::null) { LL_INFOS("Materials") << "Normal maps! " << uuid << LL_ENDL; retval = TEM_CHANGE_TEXTURE; @@ -4380,6 +4380,7 @@ S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMateri else if (pMaterialParams != tep->getMaterialParams()) { retval = LLPrimitive::setTEMaterialParams(te, pMaterialParams); + setTENormalMap(te, tep->getMaterialParams()->getNormalID()); setChanged(TEXTURE); if (mDrawable.notNull() && retval) { diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index c90ca48b01..8cf22d9808 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -1989,6 +1989,18 @@ S32 LLVOVolume::setTEGlow(const U8 te, const F32 glow) return res; } +void LLVOVolume::setTEMaterialParamsCallback(const LLMaterialID &pMaterialID, const LLMaterialPtr pMaterialParams) +{ + for (U8 i = 0; i < getNumTEs(); i++) + { + if (getTE(i)->getMaterialID() == pMaterialID) + { + LL_INFOS("Materials") << "Material params callback triggered!" << LL_ENDL; + setTEMaterialParams(i, pMaterialParams); + } + } +} + S32 LLVOVolume::setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID) { if (!pMaterialID.isNull()) @@ -1998,8 +2010,8 @@ S32 LLVOVolume::setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID) if (res) { LL_INFOS("Materials") << "We have a material!" << LL_ENDL; - LLMaterialPtr pMatParam = LLMaterialMgr::instance().get(getRegion()->getRegionID(), pMaterialID); - setTEMaterialParams(te, pMatParam); + LLMaterialMgr::instance().get(getRegion()->getRegionID(), pMaterialID, boost::bind(&LLVOVolume::setTEMaterialParamsCallback, this, _1, _2)); + //setTEMaterialParams(te, pMatParam); gPipeline.markTextured(mDrawable); mFaceMappingChanged = TRUE; } @@ -4083,7 +4095,7 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep, U8 index = facep->getTextureIndex(); - LLMaterialID matid = facep->getTextureEntry()->getMaterialID(); + const LLMaterialID* matid = &facep->getTextureEntry()->getMaterialID(); bool batchable = false; @@ -4118,7 +4130,8 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep, draw_vec[idx]->mFullbright == fullbright && draw_vec[idx]->mBump == bump && draw_vec[idx]->mTextureMatrix == tex_mat && - draw_vec[idx]->mModelMatrix == model_mat) + draw_vec[idx]->mModelMatrix == model_mat && + draw_vec[idx]->mMaterialID == matid) { draw_vec[idx]->mCount += facep->getIndicesCount(); draw_vec[idx]->mEnd += facep->getGeomCount(); @@ -4146,22 +4159,25 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep, draw_vec.push_back(draw_info); draw_info->mTextureMatrix = tex_mat; draw_info->mModelMatrix = model_mat; - - if (!facep->getTextureEntry()->getMaterialID().isNull() && facep->getTextureEntry()->getMaterialParams() != NULL) - { - // We have a material. Update our draw info accordingly. - //draw_info->mMaterialID = facep->getTextureEntry()->getMaterialID(); - LLVector4 specColor; - specColor.mV[0] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[0] * (1.0 / 255); - specColor.mV[1] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[1] * (1.0 / 255); - specColor.mV[2] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[2] * (1.0 / 255); - specColor.mV[3] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightExponent() * (1.0 / 255); - draw_info->mSpecColor = specColor; - draw_info->mEnvIntensity = facep->getTextureEntry()->getMaterialParams()->getEnvironmentIntensity() * (1.0 / 255); - draw_info->mAlphaMaskCutoff = facep->getTextureEntry()->getMaterialParams()->getAlphaMaskCutoff() * (1.0 / 255); - draw_info->mDiffuseAlphaMode = facep->getTextureEntry()->getMaterialParams()->getDiffuseAlphaMode(); - draw_info->mNormalMap = facep->getViewerObject()->getTENormalMap(facep->getTextureIndex()); - draw_info->mSpecularMap = facep->getViewerObject()->getTESpecularMap(facep->getTextureIndex()); + if (!facep->getTextureEntry()->getMaterialID().isNull()) + { + + if (facep->getTextureEntry()->getMaterialParams() != NULL) + { + // We have a material. Update our draw info accordingly. + draw_info->mMaterialID = &facep->getTextureEntry()->getMaterialID(); + LLVector4 specColor; + specColor.mV[0] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[0] * (1.0 / 255); + specColor.mV[1] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[1] * (1.0 / 255); + specColor.mV[2] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[2] * (1.0 / 255); + specColor.mV[3] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightExponent() * (1.0 / 255); + draw_info->mSpecColor = specColor; + draw_info->mEnvIntensity = facep->getTextureEntry()->getMaterialParams()->getEnvironmentIntensity() * (1.0 / 255); + draw_info->mAlphaMaskCutoff = facep->getTextureEntry()->getMaterialParams()->getAlphaMaskCutoff() * (1.0 / 255); + draw_info->mDiffuseAlphaMode = facep->getTextureEntry()->getMaterialParams()->getDiffuseAlphaMode(); + draw_info->mNormalMap = facep->getViewerObject()->getTENormalMap(facep->getTextureIndex()); + draw_info->mSpecularMap = facep->getViewerObject()->getTESpecularMap(facep->getTextureIndex()); + } } if (type == LLRenderPass::PASS_ALPHA) diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h index c996fac6f2..d1bfefdc70 100644 --- a/indra/newview/llvovolume.h +++ b/indra/newview/llvovolume.h @@ -187,6 +187,7 @@ public: /*virtual*/ S32 setTEMediaFlags(const U8 te, const U8 media_flags); /*virtual*/ S32 setTEGlow(const U8 te, const F32 glow); /*virtual*/ S32 setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID); + void setTEMaterialParamsCallback(const LLMaterialID& pMaterialID, const LLMaterialPtr pMaterialParams); /*virtual*/ S32 setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams); /*virtual*/ S32 setTEScale(const U8 te, const F32 s, const F32 t); /*virtual*/ S32 setTEScaleS(const U8 te, const F32 s); -- cgit v1.2.3