From 2b57bed899b7ca14aa23bf78a92539422d145767 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Thu, 9 Jun 2016 12:51:43 -0500 Subject: [PATCH 1/4] level-wide accumulation assignment - overidden if an object's origin is in an accumulationVolume. ** do note changing the value does require nudging a mesh and/or a level reload to kick in at time of writing for visual feedback. --- Engine/source/T3D/accumulationVolume.cpp | 6 +++-- Engine/source/T3D/levelInfo.cpp | 33 +++++++++++++++++++++++- Engine/source/T3D/levelInfo.h | 12 ++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Engine/source/T3D/accumulationVolume.cpp b/Engine/source/T3D/accumulationVolume.cpp index 7eef90634..f868207e6 100644 --- a/Engine/source/T3D/accumulationVolume.cpp +++ b/Engine/source/T3D/accumulationVolume.cpp @@ -46,6 +46,8 @@ Vector< SimObjectPtr > AccumulationVolume::smAccuObjects; Vector< SimObjectPtr > AccumulationVolume::smAccuVolumes; +GFXTexHandle gLevelAccuMap; + //#define DEBUG_DRAW IMPLEMENT_CO_NETOBJECT_V1( AccumulationVolume ); @@ -295,7 +297,7 @@ void AccumulationVolume::refreshVolumes() { SimObjectPtr object = smAccuObjects[n]; if ( object.isValid() ) - object->mAccuTex = GFXTexHandle::ZERO; + object->mAccuTex = gLevelAccuMap; } // @@ -336,7 +338,7 @@ void AccumulationVolume::updateObject(SceneObject* object) // We use ZERO instead of NULL so the accumulation // texture will be updated in renderMeshMgr. - object->mAccuTex = GFXTexHandle::ZERO; + object->mAccuTex = gLevelAccuMap; for (S32 i = 0; i < smAccuVolumes.size(); ++i) { diff --git a/Engine/source/T3D/levelInfo.cpp b/Engine/source/T3D/levelInfo.cpp index 33cd44f18..55c3b834f 100644 --- a/Engine/source/T3D/levelInfo.cpp +++ b/Engine/source/T3D/levelInfo.cpp @@ -69,6 +69,8 @@ extern ColorI gCanvasClearColor; /// @see DecalManager extern F32 gDecalBias; +/// @see AccumulationVolume +extern GFXTexHandle gLevelAccuMap; /// Default SFXAmbience used to reset the global soundscape. static SFXAmbience sDefaultAmbience; @@ -96,6 +98,8 @@ LevelInfo::LevelInfo() mNetFlags.set( ScopeAlways | Ghostable ); mAdvancedLightmapSupport = false; + mAccuTextureName = ""; + mAccuTexture = NULL; // Register with the light manager activation signal, and we need to do it first // so the advanced light bin manager can be instructed about MRT lightmaps @@ -157,6 +161,9 @@ void LevelInfo::initPersistFields() addField( "advancedLightmapSupport", TypeBool, Offset( mAdvancedLightmapSupport, LevelInfo ), "Enable expanded support for mixing static and dynamic lighting (more costly)" ); + addProtectedField("AccuTexture", TypeStringFilename, Offset(mAccuTextureName, LevelInfo), + &_setLevelAccuTexture, &defaultProtectedGetFn, "Accumulation texture."); + endGroup( "Lighting" ); addGroup( "Sound" ); @@ -203,7 +210,8 @@ U32 LevelInfo::packUpdate(NetConnection *conn, U32 mask, BitStream *stream) sfxWrite( stream, mSoundAmbience ); stream->writeInt( mSoundDistanceModel, 1 ); - + + stream->write(mAccuTextureName); return retMask; } @@ -248,6 +256,8 @@ void LevelInfo::unpackUpdate(NetConnection *conn, BitStream *stream) SFX->setDistanceModel( mSoundDistanceModel ); } + stream->read(&mAccuTextureName); + setLevelAccuTexture(mAccuTextureName); } //----------------------------------------------------------------------------- @@ -341,4 +351,25 @@ void LevelInfo::_onLMActivate(const char *lm, bool enable) lightMgr->getLightBinManager()->MRTLightmapsDuringPrePass(mAdvancedLightmapSupport); } #endif +} + +bool LevelInfo::_setLevelAccuTexture(void *object, const char *index, const char *data) +{ + LevelInfo* volume = reinterpret_cast< LevelInfo* >(object); + volume->setLevelAccuTexture(data); + return false; +} + + +void LevelInfo::setLevelAccuTexture(const String& name) +{ + mAccuTextureName = name; + if (isClientObject() && mAccuTextureName.isNotEmpty()) + { + mAccuTexture.set(mAccuTextureName, &GFXDefaultStaticDiffuseProfile, "AccumulationVolume::mAccuTexture"); + if (mAccuTexture.isNull()) + Con::warnf("AccumulationVolume::setTexture - Unable to load texture: %s", mAccuTextureName.c_str()); + else + gLevelAccuMap = mAccuTexture; + } } \ No newline at end of file diff --git a/Engine/source/T3D/levelInfo.h b/Engine/source/T3D/levelInfo.h index cc4459ae4..dbdaec941 100644 --- a/Engine/source/T3D/levelInfo.h +++ b/Engine/source/T3D/levelInfo.h @@ -36,6 +36,10 @@ #include "sfx/sfxCommon.h" #endif +#ifndef _GFXTEXTUREHANDLE_H_ +#include "gfx/gfxTextureHandle.h" +#endif + class SFXAmbience; class SFXSoundscape; @@ -96,6 +100,9 @@ class LevelInfo : public NetObject void _updateSceneGraph(); void _onLMActivate(const char *lm, bool enable); + protected: + // Name (path) of the accumulation texture. + String mAccuTextureName; public: @@ -130,9 +137,12 @@ class LevelInfo : public NetObject UpdateMask = BIT(0) }; + GFXTexHandle mAccuTexture; + virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ); virtual void unpackUpdate( NetConnection *conn, BitStream *stream ); - + static bool _setLevelAccuTexture(void *object, const char *index, const char *data); + void setLevelAccuTexture(const String& name); /// @} }; From 2237a136795aa50786678c789d250f0ca11e211e Mon Sep 17 00:00:00 2001 From: Azaezel Date: Sun, 19 Jun 2016 16:59:16 -0500 Subject: [PATCH 2/4] memleak fix --- Engine/source/T3D/levelInfo.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Engine/source/T3D/levelInfo.cpp b/Engine/source/T3D/levelInfo.cpp index 55c3b834f..98b4d524c 100644 --- a/Engine/source/T3D/levelInfo.cpp +++ b/Engine/source/T3D/levelInfo.cpp @@ -111,6 +111,11 @@ LevelInfo::LevelInfo() LevelInfo::~LevelInfo() { LightManager::smActivateSignal.remove(this, &LevelInfo::_onLMActivate); + if (!mAccuTexture.isNull()) + { + mAccuTexture.free(); + gLevelAccuMap.free(); + } } //----------------------------------------------------------------------------- From 9a4acc8a467f81622e1eafbd7b4ee312b0a32226 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Mon, 20 Jun 2016 16:47:01 -0500 Subject: [PATCH 3/4] initial assignment cleanup (also shapebase for staticShape et al) --- Engine/source/T3D/shapeBase.cpp | 6 +++++- Engine/source/T3D/tsStatic.cpp | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Engine/source/T3D/shapeBase.cpp b/Engine/source/T3D/shapeBase.cpp index 6f40cc134..6de7a0a04 100644 --- a/Engine/source/T3D/shapeBase.cpp +++ b/Engine/source/T3D/shapeBase.cpp @@ -1044,7 +1044,11 @@ bool ShapeBase::onAdd() if(mDataBlock->cloakTexName != StringTable->insert("")) mCloakTexture = TextureHandle(mDataBlock->cloakTexName, MeshTexture, false); */ - + // Accumulation and environment mapping + if (isClientObject() && mShapeInstance) + { + AccumulationVolume::addObject(this); + } return true; } diff --git a/Engine/source/T3D/tsStatic.cpp b/Engine/source/T3D/tsStatic.cpp index 78240ce16..3cf7387eb 100644 --- a/Engine/source/T3D/tsStatic.cpp +++ b/Engine/source/T3D/tsStatic.cpp @@ -310,11 +310,10 @@ bool TSStatic::onAdd() _updateShouldTick(); - // Accumulation - if ( isClientObject() && mShapeInstance ) + // Accumulation and environment mapping + if (isClientObject() && mShapeInstance) { - if ( mShapeInstance->hasAccumulation() ) - AccumulationVolume::addObject(this); + AccumulationVolume::addObject(this); } return true; From e0e1cbb3be57978731fa8f67744323c3bc1cb590 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Mon, 20 Jun 2016 17:02:34 -0500 Subject: [PATCH 4/4] force a volume refresh on levelinfo AccuTexture change --- Engine/source/T3D/levelInfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Engine/source/T3D/levelInfo.cpp b/Engine/source/T3D/levelInfo.cpp index 98b4d524c..7d275585a 100644 --- a/Engine/source/T3D/levelInfo.cpp +++ b/Engine/source/T3D/levelInfo.cpp @@ -36,7 +36,7 @@ #include "math/mathIO.h" #include "torqueConfig.h" - +#include "T3D/accumulationVolume.h" IMPLEMENT_CO_NETOBJECT_V1(LevelInfo); @@ -377,4 +377,5 @@ void LevelInfo::setLevelAccuTexture(const String& name) else gLevelAccuMap = mAccuTexture; } + AccumulationVolume::refreshVolumes(); } \ No newline at end of file