mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
Added ability to pass ints to post effect shader consts
Reorg'd probe init to flow better and be more robust on load Cleaned up various parts of the probe render manager to be more stable Fixed issue with crash on release due to numProbe in loops being 0 Updated glsl probe array shader Beginning of rework of editor settings Beginning of conversion of asset import config to similar system as editor settings
This commit is contained in:
parent
b40d33a663
commit
dd3422b5a2
21 changed files with 300 additions and 420 deletions
|
|
@ -89,7 +89,11 @@ ImplementEnumType(ReflectionModeEnum,
|
|||
//-----------------------------------------------------------------------------
|
||||
// Object setup and teardown
|
||||
//-----------------------------------------------------------------------------
|
||||
ReflectionProbe::ReflectionProbe()
|
||||
ReflectionProbe::ReflectionProbe() :
|
||||
cubeDescId(0),
|
||||
reflectorDesc(nullptr),
|
||||
mSphereVertCount(0),
|
||||
mSpherePrimitiveCount(0)
|
||||
{
|
||||
// Flag this object so that it will always
|
||||
// be sent across the network to clients
|
||||
|
|
@ -247,11 +251,11 @@ bool ReflectionProbe::_setReflectionMode(void *object, const char *index, const
|
|||
{
|
||||
ReflectionProbe* probe = reinterpret_cast<ReflectionProbe*>(object);
|
||||
|
||||
if (data == "Static Cubemap")
|
||||
if (!dStrcmp(data,"Static Cubemap"))
|
||||
{
|
||||
probe->mReflectionModeType = StaticCubemap;
|
||||
}
|
||||
else if (data == "Baked Cubemap")
|
||||
else if (!dStrcmp(data, "Baked Cubemap"))
|
||||
{
|
||||
//Clear our cubemap if we changed it to be baked, just for cleanliness
|
||||
probe->mReflectionModeType = BakedCubemap;
|
||||
|
|
@ -589,6 +593,8 @@ void ReflectionProbe::processDynamicCubemap()
|
|||
else
|
||||
mProbeInfo->mIsEnabled = false;
|
||||
|
||||
mCubemapDirty = false;
|
||||
|
||||
//Update the probe manager with our new texture!
|
||||
//if (!mProbeInfo->mIsSkylight && mProbeInfo->mPrefilterCubemap->isInitialized() && mProbeInfo->mIrradianceCubemap->isInitialized())
|
||||
// PROBEMGR->updateProbeTexture(mProbeInfo->mProbeIdx);
|
||||
|
|
@ -637,8 +643,10 @@ void ReflectionProbe::processBakedCubemap()
|
|||
{
|
||||
mProbeInfo->mIsEnabled = true;
|
||||
|
||||
mCubemapDirty = false;
|
||||
|
||||
//Update the probe manager with our new texture!
|
||||
PROBEMGR->updateProbeTexture(mProbeInfo->mProbeIdx);
|
||||
PROBEMGR->updateProbeTexture(mProbeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -728,8 +736,10 @@ void ReflectionProbe::processStaticCubemap()
|
|||
{
|
||||
mProbeInfo->mIsEnabled = true;
|
||||
|
||||
mCubemapDirty = false;
|
||||
|
||||
//Update the probe manager with our new texture!
|
||||
PROBEMGR->updateProbeTexture(mProbeInfo->mProbeIdx);
|
||||
PROBEMGR->updateProbeTexture(mProbeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,9 +151,6 @@ protected:
|
|||
U32 mDynamicLastBakeMS;
|
||||
U32 mRefreshRateMS;
|
||||
|
||||
GBitmap* mCubeFaceBitmaps[6];
|
||||
U32 mCubemapResolution;
|
||||
|
||||
F32 mMaxDrawDistance;
|
||||
|
||||
bool mResourcesCreated;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#include "gfx/D3D11/gfxD3D11EnumTranslate.h"
|
||||
#include "gfx/bitmap/imageUtils.h"
|
||||
|
||||
GFXD3D11Cubemap::GFXD3D11Cubemap() : mTexture(NULL), mSRView(NULL), mDSView(NULL)
|
||||
GFXD3D11Cubemap::GFXD3D11Cubemap() : mTexture(NULL), mSRView(NULL), mDSView(NULL), mTexSize(0)
|
||||
{
|
||||
mDynamic = false;
|
||||
mAutoGenMips = false;
|
||||
|
|
@ -568,4 +568,4 @@ void GFXD3D11CubemapArray::zombify()
|
|||
void GFXD3D11CubemapArray::resurrect()
|
||||
{
|
||||
// Static cubemaps are handled by D3D
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -541,4 +541,4 @@ MaterialParameters* ProcessedCustomMaterial::allocMaterialParameters()
|
|||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1360,7 +1360,7 @@ void ProcessedShaderMaterial::setSceneInfo(SceneRenderState * state, const Scene
|
|||
|
||||
LIGHTMGR->setLightInfo(this, mMaterial, sgData, state, pass, shaderConsts);
|
||||
|
||||
PROBEMGR->setProbeInfo(this, mMaterial, sgData, state, pass, shaderConsts);
|
||||
//PROBEMGR->setProbeInfo(this, mMaterial, sgData, state, pass, shaderConsts);
|
||||
}
|
||||
|
||||
void ProcessedShaderMaterial::setBuffers( GFXVertexBufferHandleBase *vertBuffer, GFXPrimitiveBufferHandle *primBuffer )
|
||||
|
|
|
|||
|
|
@ -183,6 +183,16 @@ void PostEffect::EffectConst::set(const F32 &newVal)
|
|||
mValueType = FloatType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::set(const int& newVal)
|
||||
{
|
||||
if (mIntVal == newVal)
|
||||
return;
|
||||
|
||||
mIntVal = newVal;
|
||||
mDirty = true;
|
||||
mValueType = IntType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::set(const Point4F &newVal)
|
||||
{
|
||||
if (mPointVal == newVal)
|
||||
|
|
@ -326,6 +336,21 @@ void PostEffect::EffectConst::setToBuffer( GFXShaderConstBufferRef buff )
|
|||
const char* err = avar("PostEffect::EffectConst::setToBuffer $s type is not implemented", mName.c_str());
|
||||
Con::errorf(err);
|
||||
GFXAssertFatal(0, err);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (mValueType == IntType)
|
||||
{
|
||||
if (type == GFXSCT_Int)
|
||||
{
|
||||
buff->set(mHandle, mIntVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if TORQUE_DEBUG
|
||||
const char* err = avar("PostEffect::EffectConst::setToBuffer $s type is not implemented", mName.c_str());
|
||||
Con::errorf(err);
|
||||
GFXAssertFatal(0, err);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -1676,6 +1701,20 @@ void PostEffect::setShaderConst(const String &name, const F32 &val)
|
|||
iter->value->set(val);
|
||||
}
|
||||
|
||||
void PostEffect::setShaderConst(const String& name, const int& val)
|
||||
{
|
||||
PROFILE_SCOPE(PostEffect_SetShaderConst_Float);
|
||||
|
||||
EffectConstTable::Iterator iter = mEffectConsts.find(name);
|
||||
if (iter == mEffectConsts.end())
|
||||
{
|
||||
EffectConst* newConst = new EffectConst(name, val);
|
||||
iter = mEffectConsts.insertUnique(name, newConst);
|
||||
}
|
||||
|
||||
iter->value->set(val);
|
||||
}
|
||||
|
||||
void PostEffect::setShaderConst(const String &name, const Point4F &val)
|
||||
{
|
||||
PROFILE_SCOPE(PostEffect_SetShaderConst_Point);
|
||||
|
|
|
|||
|
|
@ -230,6 +230,14 @@ protected:
|
|||
set(val);
|
||||
}
|
||||
|
||||
EffectConst(const String& name, const int& val)
|
||||
: mName(name),
|
||||
mHandle(NULL),
|
||||
mDirty(true)
|
||||
{
|
||||
set(val);
|
||||
}
|
||||
|
||||
EffectConst(const String &name, const Point4F &val)
|
||||
: mName(name),
|
||||
mHandle(NULL),
|
||||
|
|
@ -264,6 +272,7 @@ protected:
|
|||
|
||||
void set( const String &newVal );
|
||||
void set(const F32 &newVal);
|
||||
void set(const int& newVal);
|
||||
void set(const Point4F &newVal);
|
||||
void set(const MatrixF &newVal);
|
||||
void set(const Vector<Point4F> &newVal);
|
||||
|
|
@ -277,6 +286,7 @@ protected:
|
|||
|
||||
String mStringVal;
|
||||
|
||||
S32 mIntVal;
|
||||
F32 mFloatVal;
|
||||
Point4F mPointVal;
|
||||
MatrixF mMatrixVal;
|
||||
|
|
@ -287,6 +297,7 @@ protected:
|
|||
enum
|
||||
{
|
||||
StringType,
|
||||
IntType,
|
||||
FloatType,
|
||||
PointType,
|
||||
MatrixType,
|
||||
|
|
@ -427,6 +438,7 @@ public:
|
|||
///
|
||||
void setShaderConst( const String &name, const String &val );
|
||||
void setShaderConst(const String &name, const F32 &val);
|
||||
void setShaderConst(const String& name, const int& val);
|
||||
void setShaderConst(const String &name, const Point4F &val);
|
||||
void setShaderConst(const String &name, const MatrixF &val);
|
||||
void setShaderConst(const String &name, const Vector<Point4F> &val);
|
||||
|
|
|
|||
|
|
@ -87,7 +87,8 @@ ProbeRenderInst::ProbeRenderInst() :
|
|||
mAtten(0.0),
|
||||
mCubemapIndex(0),
|
||||
mIsSkylight(false),
|
||||
mProbeIdx(0)
|
||||
mProbeIdx(0),
|
||||
mProbeShapeType(Box)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +133,8 @@ ProbeShaderConstants::ProbeShaderConstants()
|
|||
mBRDFTextureMap(NULL),
|
||||
mSkylightSpecularMap(NULL),
|
||||
mSkylightIrradMap(NULL),
|
||||
mHasSkylight(NULL)
|
||||
mHasSkylight(NULL),
|
||||
mWorldToObjArraySC(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +204,10 @@ RenderProbeMgr::RenderProbeMgr()
|
|||
mLastShader(nullptr),
|
||||
mLastConstants(nullptr),
|
||||
mProbesDirty(false),
|
||||
mHasSkylight(false)
|
||||
mHasSkylight(false),
|
||||
mSkylightCubemapIdx(-1),
|
||||
mCubeMapCount(0),
|
||||
mDefaultSkyLight(nullptr)
|
||||
{
|
||||
mEffectiveProbeCount = 0;
|
||||
mMipCount = 0;
|
||||
|
|
@ -376,7 +381,7 @@ void RenderProbeMgr::unregisterProbe(U32 probeIdx)
|
|||
mRegisteredProbes.erase(probeIdx);
|
||||
|
||||
//rebuild our probe data
|
||||
_setupStaticParameters();
|
||||
mProbesDirty = true;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -409,7 +414,7 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
U32 probeCount = mRegisteredProbes.size();
|
||||
|
||||
mEffectiveProbeCount = 0;
|
||||
mMipCount = 0;
|
||||
mMipCount = 1;
|
||||
|
||||
mHasSkylight = false;
|
||||
mSkylightCubemapIdx = -1;
|
||||
|
|
@ -429,11 +434,7 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
probeWorldToObjData.fill(MatrixF::Identity);
|
||||
probeBBMinData.fill(Point4F::Zero);
|
||||
probeBBMaxData.fill(Point4F::Zero);
|
||||
probeConfigData.fill(Point4F::Zero);
|
||||
|
||||
Vector<U32> cubemapIdxes;
|
||||
|
||||
mMipCount = 1;
|
||||
probeConfigData.fill(Point4F(-1,0,0,0));
|
||||
|
||||
for (U32 i = 0; i < probeCount; i++)
|
||||
{
|
||||
|
|
@ -444,13 +445,12 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
if (!curEntry.mIsEnabled)
|
||||
continue;
|
||||
|
||||
U32 mips = mRegisteredProbes[0].mPrefilterCubemap.getPointer()->getMipMapLevels();
|
||||
mMipCount = mips != 0 && mips > mMipCount ? mips : 0;
|
||||
U32 mips = mRegisteredProbes[i].mPrefilterCubemap.getPointer()->getMipMapLevels();
|
||||
mMipCount = mips != 0 && mips >= mMipCount ? mips : 0;
|
||||
|
||||
if (curEntry.mProbeShapeType == ProbeRenderInst::ProbeShapeType::Skylight || curEntry.mIsSkylight)
|
||||
if (curEntry.mIsSkylight)
|
||||
{
|
||||
mSkylightCubemapIdx = curEntry.mCubemapIndex;
|
||||
mHasSkylight = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -471,25 +471,32 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
curEntry.mAtten,
|
||||
curEntry.mCubemapIndex);
|
||||
|
||||
cubemapIdxes.push_back(i);
|
||||
|
||||
mEffectiveProbeCount++;
|
||||
}
|
||||
|
||||
mProbesDirty = false;
|
||||
}
|
||||
|
||||
void RenderProbeMgr::updateProbeTexture(U32 probeIdx)
|
||||
void RenderProbeMgr::updateProbeTexture(ProbeRenderInst* probeInfo)
|
||||
{
|
||||
if (probeIdx >= mRegisteredProbes.size())
|
||||
if (probeInfo->mIrradianceCubemap.isNull() || !probeInfo->mIrradianceCubemap->isInitialized())
|
||||
{
|
||||
Con::errorf("RenderProbeMgr::updateProbeTexture() - tried to update a probe's texture with an invalid or uninitialized irradiance map!");
|
||||
return;
|
||||
}
|
||||
|
||||
const U32 cubeIndex = mRegisteredProbes[probeIdx].mCubemapIndex;
|
||||
mIrradianceArray->updateTexture(mRegisteredProbes[probeIdx].mIrradianceCubemap, cubeIndex);
|
||||
mPrefilterArray->updateTexture(mRegisteredProbes[probeIdx].mPrefilterCubemap, cubeIndex);
|
||||
if (probeInfo->mPrefilterCubemap.isNull() || !probeInfo->mPrefilterCubemap->isInitialized())
|
||||
{
|
||||
Con::errorf("RenderProbeMgr::updateProbeTexture() - tried to update a probe's texture with an invalid or uninitialized specular map!");
|
||||
return;
|
||||
}
|
||||
|
||||
Con::warnf("UpdatedProbeTexture - probeIdx: %u on cubeIndex %u, Irrad validity: %d, Prefilter validity: %d", probeIdx, cubeIndex,
|
||||
mRegisteredProbes[probeIdx].mIrradianceCubemap->isInitialized(), mRegisteredProbes[probeIdx].mPrefilterCubemap->isInitialized());
|
||||
const U32 cubeIndex = probeInfo->mCubemapIndex;
|
||||
mIrradianceArray->updateTexture(probeInfo->mIrradianceCubemap, cubeIndex);
|
||||
mPrefilterArray->updateTexture(probeInfo->mPrefilterCubemap, cubeIndex);
|
||||
|
||||
Con::warnf("UpdatedProbeTexture - probeIdx: %u on cubeIndex %u, Irrad validity: %d, Prefilter validity: %d", probeInfo->mProbeIdx, cubeIndex,
|
||||
probeInfo->mIrradianceCubemap->isInitialized(), probeInfo->mPrefilterCubemap->isInitialized());
|
||||
}
|
||||
|
||||
void RenderProbeMgr::_setupPerFrameParameters(const SceneRenderState *state)
|
||||
|
|
@ -669,7 +676,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
|
||||
if (curEntry.mIsSkylight)
|
||||
{
|
||||
if (curEntry.mPrefilterCubemap.isValid() && curEntry.mPrefilterCubemap.isValid())
|
||||
if (curEntry.mPrefilterCubemap->isInitialized() && curEntry.mIrradianceCubemap->isInitialized())
|
||||
{
|
||||
GFX->setCubeTexture(probeShaderConsts->mSkylightSpecularMap->getSamplerRegister(), curEntry.mPrefilterCubemap);
|
||||
GFX->setCubeTexture(probeShaderConsts->mSkylightIrradMap->getSamplerRegister(), curEntry.mIrradianceCubemap);
|
||||
|
|
@ -739,7 +746,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
_setupStaticParameters();
|
||||
|
||||
// Early out if nothing to draw.
|
||||
if (!RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (mRegisteredProbes.size() == 0 || (mEffectiveProbeCount == 0 && !mHasSkylight)))
|
||||
if (!RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (mEffectiveProbeCount == 0 && mSkylightCubemapIdx == -1))
|
||||
{
|
||||
getProbeArrayEffect()->setSkip(true);
|
||||
return;
|
||||
|
|
@ -765,23 +772,24 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
|
||||
String useDebugContrib = Con::getVariable("$Probes::showProbeContrib", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_CONTRIB", useDebugContrib);
|
||||
|
||||
if(mHasSkylight && mEffectiveProbeCount == 0)
|
||||
mProbeArrayEffect->setShaderMacro("SKYLIGHT_ONLY", "1");
|
||||
|
||||
if (mHasSkylight || mEffectiveProbeCount != 0)
|
||||
{
|
||||
mProbeArrayEffect->setTexture(3, mBRDFTexture);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
|
||||
}
|
||||
mProbeArrayEffect->setTexture(3, mBRDFTexture);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$hasSkylight", (float)mHasSkylight);
|
||||
if (mHasSkylight)
|
||||
{
|
||||
mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", mSkylightCubemapIdx);
|
||||
}
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
||||
mProbeArrayEffect->setShaderConst("$numProbes", (S32)mEffectiveProbeCount);
|
||||
mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", mSkylightCubemapIdx);
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
|
||||
|
||||
//also set up some colors
|
||||
Vector<Point4F> contribColors;
|
||||
|
||||
contribColors.setSize(MAXPROBECOUNT);
|
||||
|
||||
if (mEffectiveProbeCount != 0)
|
||||
{
|
||||
if (useDebugContrib == String("1"))
|
||||
|
|
@ -789,11 +797,6 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
MRandomLCG RandomGen;
|
||||
RandomGen.setSeed(mEffectiveProbeCount);
|
||||
|
||||
//also set up some colors
|
||||
Vector<Point4F> contribColors;
|
||||
|
||||
contribColors.setSize(MAXPROBECOUNT);
|
||||
|
||||
for (U32 i = 0; i < mEffectiveProbeCount; i++)
|
||||
{
|
||||
//we're going to cheat here a little for consistent debugging behavior. The first 3 probes will always have R G and then B for their colors, every other will be random
|
||||
|
|
@ -806,18 +809,18 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
else
|
||||
contribColors[i] = Point4F(RandomGen.randF(0, 1), RandomGen.randF(0, 1), RandomGen.randF(0, 1), 1);
|
||||
}
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$probeContribColors", contribColors);
|
||||
}
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$inRefPosArray", probeRefPositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
|
||||
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMinData);
|
||||
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMaxData);
|
||||
mProbeArrayEffect->setShaderConst("$probeConfigData", probeConfigData);
|
||||
}
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$probeContribColors", contribColors);
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$inRefPosArray", probeRefPositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
|
||||
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMinData);
|
||||
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMaxData);
|
||||
mProbeArrayEffect->setShaderConst("$probeConfigData", probeConfigData);
|
||||
|
||||
// Make sure the effect is gonna render.
|
||||
getProbeArrayEffect()->setSkip(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ public:
|
|||
U32 pass,
|
||||
GFXShaderConstBuffer *shaderConsts);
|
||||
|
||||
void updateProbeTexture(U32 probeIdx);
|
||||
void updateProbeTexture(ProbeRenderInst* probeInfo);
|
||||
|
||||
/// Debug rendering
|
||||
static bool smRenderReflectionProbes;
|
||||
|
|
|
|||
|
|
@ -709,4 +709,4 @@ DefineEngineMethod(Settings, clearGroups, void, (), , "settingObj.clearGroups();
|
|||
DefineEngineMethod(Settings, getCurrentGroups, const char*, (), , "settingObj.getCurrentGroups();")
|
||||
{
|
||||
return object->getCurrentGroups();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue