mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Updated the PostFX ability to setShaderConsts and cubetextures for probes
This commit is contained in:
parent
64db2b1d15
commit
fd8840ff53
|
|
@ -170,6 +170,57 @@ void PostEffect::EffectConst::set( const String &newVal )
|
|||
|
||||
mStringVal = newVal;
|
||||
mDirty = true;
|
||||
mValueType = StringType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::set(const F32 &newVal)
|
||||
{
|
||||
if (mFloatVal == newVal)
|
||||
return;
|
||||
|
||||
mFloatVal = newVal;
|
||||
mDirty = true;
|
||||
mValueType = FloatType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::set(const Point4F &newVal)
|
||||
{
|
||||
if (mPointVal == newVal)
|
||||
return;
|
||||
|
||||
mPointVal = newVal;
|
||||
mDirty = true;
|
||||
mValueType = PointType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::set(const MatrixF &newVal)
|
||||
{
|
||||
if (mMatrixVal == newVal)
|
||||
return;
|
||||
|
||||
mMatrixVal = newVal;
|
||||
mDirty = true;
|
||||
mValueType = MatrixType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::set(const Vector<Point4F> &newVal)
|
||||
{
|
||||
//if (mPointArrayVal == newVal)
|
||||
// return;
|
||||
|
||||
mPointArrayVal = newVal;
|
||||
mDirty = true;
|
||||
mValueType = PointArrayType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::set(const Vector<MatrixF> &newVal)
|
||||
{
|
||||
//if (mMatrixArrayVal == newVal)
|
||||
// return;
|
||||
|
||||
mMatrixArrayVal = newVal;
|
||||
mDirty = true;
|
||||
mValueType = MatrixArrayType;
|
||||
}
|
||||
|
||||
void PostEffect::EffectConst::setToBuffer( GFXShaderConstBufferRef buff )
|
||||
|
|
@ -194,71 +245,179 @@ void PostEffect::EffectConst::setToBuffer( GFXShaderConstBufferRef buff )
|
|||
// Expand to other types as necessary.
|
||||
U32 arraySize = mHandle->getArraySize();
|
||||
|
||||
const char *strVal = mStringVal.c_str();
|
||||
if (mValueType == StringType)
|
||||
{
|
||||
const char *strVal = mStringVal.c_str();
|
||||
|
||||
if ( type == GFXSCT_Int )
|
||||
{
|
||||
S32 val;
|
||||
Con::setData( TypeS32, &val, 0, 1, &strVal );
|
||||
buff->set( mHandle, val );
|
||||
}
|
||||
else if ( type == GFXSCT_Float )
|
||||
{
|
||||
F32 val;
|
||||
Con::setData( TypeF32, &val, 0, 1, &strVal );
|
||||
buff->set( mHandle, val );
|
||||
}
|
||||
else if ( type == GFXSCT_Float2 )
|
||||
{
|
||||
Point2F val;
|
||||
Con::setData( TypePoint2F, &val, 0, 1, &strVal );
|
||||
buff->set( mHandle, val );
|
||||
}
|
||||
else if ( type == GFXSCT_Float3 )
|
||||
{
|
||||
Point3F val;
|
||||
Con::setData( TypePoint3F, &val, 0, 1, &strVal );
|
||||
buff->set( mHandle, val );
|
||||
}
|
||||
else if ( type == GFXSCT_Float4 )
|
||||
{
|
||||
Point4F val;
|
||||
|
||||
if ( arraySize > 1 )
|
||||
if (type == GFXSCT_Int)
|
||||
{
|
||||
// Do array setup!
|
||||
//U32 unitCount = StringUnit::getUnitCount( strVal, "\t" );
|
||||
//AssertFatal( unitCount == arraySize, "" );
|
||||
S32 val;
|
||||
Con::setData(TypeS32, &val, 0, 1, &strVal);
|
||||
buff->set(mHandle, val);
|
||||
}
|
||||
else if (type == GFXSCT_Float)
|
||||
{
|
||||
F32 val;
|
||||
Con::setData(TypeF32, &val, 0, 1, &strVal);
|
||||
buff->set(mHandle, val);
|
||||
}
|
||||
else if (type == GFXSCT_Float2)
|
||||
{
|
||||
Point2F val;
|
||||
Con::setData(TypePoint2F, &val, 0, 1, &strVal);
|
||||
buff->set(mHandle, val);
|
||||
}
|
||||
else if (type == GFXSCT_Float3)
|
||||
{
|
||||
Point3F val;
|
||||
Con::setData(TypePoint3F, &val, 0, 1, &strVal);
|
||||
buff->set(mHandle, val);
|
||||
}
|
||||
else if (type == GFXSCT_Float4)
|
||||
{
|
||||
Point4F val;
|
||||
|
||||
String tmpString;
|
||||
Vector<Point4F> valArray;
|
||||
|
||||
for ( U32 i = 0; i < arraySize; i++ )
|
||||
if (arraySize > 1)
|
||||
{
|
||||
tmpString = StringUnit::getUnit( strVal, i, "\t" );
|
||||
valArray.increment();
|
||||
const char *tmpCStr = tmpString.c_str();
|
||||
// Do array setup!
|
||||
//U32 unitCount = StringUnit::getUnitCount( strVal, "\t" );
|
||||
//AssertFatal( unitCount == arraySize, "" );
|
||||
|
||||
Con::setData( TypePoint4F, &valArray.last(), 0, 1, &tmpCStr );
|
||||
String tmpString;
|
||||
Vector<Point4F> valArray;
|
||||
|
||||
for (U32 i = 0; i < arraySize; i++)
|
||||
{
|
||||
tmpString = StringUnit::getUnit(strVal, i, "\t");
|
||||
valArray.increment();
|
||||
const char *tmpCStr = tmpString.c_str();
|
||||
|
||||
Con::setData(TypePoint4F, &valArray.last(), 0, 1, &tmpCStr);
|
||||
}
|
||||
|
||||
AlignedArray<Point4F> rectData(valArray.size(), sizeof(Point4F), (U8*)valArray.address(), false);
|
||||
buff->set(mHandle, rectData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do regular setup.
|
||||
Con::setData(TypePoint4F, &val, 0, 1, &strVal);
|
||||
buff->set(mHandle, val);
|
||||
}
|
||||
|
||||
AlignedArray<Point4F> rectData( valArray.size(), sizeof( Point4F ), (U8*)valArray.address(), false );
|
||||
buff->set( mHandle, rectData );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do regular setup.
|
||||
Con::setData( TypePoint4F, &val, 0, 1, &strVal );
|
||||
buff->set( mHandle, val );
|
||||
#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
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (mValueType == FloatType)
|
||||
{
|
||||
if (type == GFXSCT_Float)
|
||||
{
|
||||
buff->set(mHandle, mFloatVal);
|
||||
}
|
||||
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);
|
||||
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 == PointType)
|
||||
{
|
||||
if (type == GFXSCT_Float2)
|
||||
{
|
||||
buff->set(mHandle, Point2F(mPointVal.x, mPointVal.y));
|
||||
}
|
||||
else if (type == GFXSCT_Float3)
|
||||
{
|
||||
buff->set(mHandle, Point3F(mPointVal.x, mPointVal.y, mPointVal.z));
|
||||
}
|
||||
else if (type == GFXSCT_Float4)
|
||||
{
|
||||
buff->set(mHandle, mPointVal);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
else if (mValueType == MatrixType)
|
||||
{
|
||||
if (type == GFXSCT_Float4x4)
|
||||
{
|
||||
buff->set(mHandle, mMatrixVal);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
else if (mValueType == PointArrayType)
|
||||
{
|
||||
if (type == GFXSCT_Float4)
|
||||
{
|
||||
if (arraySize != mPointArrayVal.size())
|
||||
{
|
||||
#if TORQUE_DEBUG
|
||||
const char* err = avar("PostEffect::EffectConst::setToBuffer PointArrayType, attempted to feed an array that does not match the uniform array's size!");
|
||||
Con::errorf(err);
|
||||
GFXAssertFatal(0, err);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
AlignedArray<Point4F> alignedVal = AlignedArray<Point4F>(arraySize, sizeof(Point4F), (U8*)mPointArrayVal.address(), false);
|
||||
|
||||
buff->set(mHandle, alignedVal);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
else if (mValueType == MatrixArrayType)
|
||||
{
|
||||
if (type == GFXSCT_Float4x4)
|
||||
{
|
||||
if (arraySize != mMatrixArrayVal.size())
|
||||
{
|
||||
#if TORQUE_DEBUG
|
||||
const char* err = avar("PostEffect::EffectConst::setToBuffer MatrixArrayType, attempted to feed an array that does not match the uniform array's size!");
|
||||
Con::errorf(err);
|
||||
GFXAssertFatal(0, err);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
buff->set(mHandle, mMatrixArrayVal.address(), arraySize);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -413,6 +572,8 @@ bool PostEffect::onAdd()
|
|||
// Find additional textures
|
||||
for( S32 i = 0; i < NumTextures; i++ )
|
||||
{
|
||||
mTextureType[i] = NormalTextureType;
|
||||
|
||||
String texFilename = mTexFilename[i];
|
||||
|
||||
// Skip empty stages or ones with variable or target names.
|
||||
|
|
@ -915,6 +1076,11 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
|
|||
setShaderConsts_callback();
|
||||
}
|
||||
|
||||
if (mShaderName == String("PFX_ReflectionProbeArray") || getName() == StringTable->insert("reflectionProbeArrayPostFX"))
|
||||
{
|
||||
bool derp = true;
|
||||
}
|
||||
|
||||
EffectConstTable::Iterator iter = mEffectConsts.begin();
|
||||
for ( ; iter != mEffectConsts.end(); iter++ )
|
||||
iter->value->setToBuffer( mShaderConsts );
|
||||
|
|
@ -972,6 +1138,30 @@ void PostEffect::_setupTexture( U32 stage, GFXTexHandle &inputTex, const RectI *
|
|||
GFX->setTexture( stage, theTex );
|
||||
}
|
||||
|
||||
void PostEffect::_setupCubemapTexture(U32 stage, GFXCubemapHandle &inputTex)
|
||||
{
|
||||
RectI viewport = GFX->getViewport();
|
||||
|
||||
mActiveTextures[stage] = nullptr;
|
||||
mActiveNamedTarget[stage] = nullptr;
|
||||
mActiveTextureViewport[stage] = viewport;
|
||||
|
||||
if (inputTex.isValid())
|
||||
GFX->setCubeTexture(stage, inputTex);
|
||||
}
|
||||
|
||||
void PostEffect::_setupCubemapArrayTexture(U32 stage, GFXCubemapArrayHandle &inputTex)
|
||||
{
|
||||
RectI viewport = GFX->getViewport();
|
||||
|
||||
mActiveTextures[stage] = nullptr;
|
||||
mActiveNamedTarget[stage] = nullptr;
|
||||
mActiveTextureViewport[stage] = viewport;
|
||||
|
||||
if (inputTex.isValid())
|
||||
GFX->setCubeArrayTexture(stage, inputTex);
|
||||
}
|
||||
|
||||
void PostEffect::_setupTransforms()
|
||||
{
|
||||
// Set everything to identity.
|
||||
|
|
@ -1188,8 +1378,15 @@ void PostEffect::process( const SceneRenderState *state,
|
|||
GFXTransformSaver saver;
|
||||
|
||||
// Set the textures.
|
||||
for ( U32 i = 0; i < NumTextures; i++ )
|
||||
_setupTexture( i, inOutTex, inTexViewport );
|
||||
for (U32 i = 0; i < NumTextures; i++)
|
||||
{
|
||||
if (mTextureType[i] == NormalTextureType)
|
||||
_setupTexture(i, inOutTex, inTexViewport);
|
||||
else if (mTextureType[i] == CubemapType)
|
||||
_setupCubemapTexture(i, mCubemapTextures[i]);
|
||||
else if (mTextureType[i] == CubemapArrayType)
|
||||
_setupCubemapArrayTexture(i, mCubemapArrayTextures[i]);
|
||||
}
|
||||
|
||||
_setupStateBlock( state ) ;
|
||||
_setupTransforms();
|
||||
|
|
@ -1406,6 +1603,38 @@ void PostEffect::setTexture( U32 index, const String &texFilePath )
|
|||
|
||||
// Try to load the texture.
|
||||
mTextures[index].set( texFilePath, &PostFxTextureProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) );
|
||||
|
||||
mTextureType[index] = NormalTextureType;
|
||||
}
|
||||
|
||||
void PostEffect::setCubemapTexture(U32 index, const GFXCubemapHandle &cubemapHandle)
|
||||
{
|
||||
// Set the new texture name.
|
||||
mCubemapTextures[index].free();
|
||||
|
||||
// Skip empty stages or ones with variable or target names.
|
||||
if (cubemapHandle.isNull())
|
||||
return;
|
||||
|
||||
// Try to load the texture.
|
||||
mCubemapTextures[index] = cubemapHandle;
|
||||
|
||||
mTextureType[index] = CubemapType;
|
||||
}
|
||||
|
||||
void PostEffect::setCubemapArrayTexture(U32 index, const GFXCubemapArrayHandle &cubemapArrayHandle)
|
||||
{
|
||||
// Set the new texture name.
|
||||
mCubemapArrayTextures[index].free();
|
||||
|
||||
// Skip empty stages or ones with variable or target names.
|
||||
if (cubemapArrayHandle.isNull())
|
||||
return;
|
||||
|
||||
// Try to load the texture.
|
||||
mCubemapArrayTextures[index] = cubemapArrayHandle;
|
||||
|
||||
mTextureType[index] = CubemapArrayType;
|
||||
}
|
||||
|
||||
void PostEffect::setShaderConst( const String &name, const String &val )
|
||||
|
|
@ -1422,6 +1651,76 @@ void PostEffect::setShaderConst( const String &name, const String &val )
|
|||
iter->value->set( val );
|
||||
}
|
||||
|
||||
void PostEffect::setShaderConst(const String &name, const F32 &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);
|
||||
|
||||
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 MatrixF &val)
|
||||
{
|
||||
PROFILE_SCOPE(PostEffect_SetShaderConst_Matrix);
|
||||
|
||||
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 Vector<Point4F> &val)
|
||||
{
|
||||
PROFILE_SCOPE(PostEffect_SetShaderConst_PointArray);
|
||||
|
||||
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 Vector<MatrixF> &val)
|
||||
{
|
||||
PROFILE_SCOPE(PostEffect_SetShaderConst_MatrixArray);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
F32 PostEffect::getAspectRatio() const
|
||||
{
|
||||
const Point2I &rtSize = GFX->getActiveRenderTarget()->getSize();
|
||||
|
|
@ -1473,18 +1772,21 @@ void PostEffect::_checkRequirements()
|
|||
// they exist... else we're invalid.
|
||||
for ( U32 i=0; i < NumTextures; i++ )
|
||||
{
|
||||
const String &texFilename = mTexFilename[i];
|
||||
|
||||
if ( texFilename.isNotEmpty() && texFilename[0] == '#' )
|
||||
if (mTextureType[i] == NormalTextureType)
|
||||
{
|
||||
NamedTexTarget *namedTarget = NamedTexTarget::find( texFilename.c_str() + 1 );
|
||||
if (!namedTarget)
|
||||
const String &texFilename = mTexFilename[i];
|
||||
|
||||
if (texFilename.isNotEmpty() && texFilename[0] == '#')
|
||||
{
|
||||
return;
|
||||
NamedTexTarget *namedTarget = NamedTexTarget::find(texFilename.c_str() + 1);
|
||||
if (!namedTarget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab the macros for shader initialization.
|
||||
namedTarget->getShaderMacros(¯os);
|
||||
}
|
||||
|
||||
// Grab the macros for shader initialization.
|
||||
namedTarget->getShaderMacros( ¯os );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@
|
|||
#ifndef _GFXTEXTUREHANDLE_H_
|
||||
#include "gfx/gfxTextureHandle.h"
|
||||
#endif
|
||||
#ifndef _GFXCUBEMAP_H_
|
||||
#include "gfx/gfxCubemap.h"
|
||||
#endif
|
||||
#ifndef _GFXTARGET_H_
|
||||
#include "gfx/gfxTarget.h"
|
||||
#endif
|
||||
|
|
@ -88,7 +91,16 @@ protected:
|
|||
FileName mTexFilename[NumTextures];
|
||||
bool mTexSRGB[NumTextures];
|
||||
|
||||
enum
|
||||
{
|
||||
NormalTextureType = 0,
|
||||
CubemapType,
|
||||
CubemapArrayType,
|
||||
} mTextureType[NumTextures];
|
||||
|
||||
GFXTexHandle mTextures[NumTextures];
|
||||
GFXCubemapHandle mCubemapTextures[NumTextures];
|
||||
GFXCubemapArrayHandle mCubemapArrayTextures[NumTextures];
|
||||
|
||||
NamedTexTarget mNamedTarget;
|
||||
NamedTexTarget mNamedTargetDepthStencil;
|
||||
|
|
@ -210,7 +222,52 @@ protected:
|
|||
set( val );
|
||||
}
|
||||
|
||||
EffectConst(const String &name, const F32 &val)
|
||||
: mName(name),
|
||||
mHandle(NULL),
|
||||
mDirty(true)
|
||||
{
|
||||
set(val);
|
||||
}
|
||||
|
||||
EffectConst(const String &name, const Point4F &val)
|
||||
: mName(name),
|
||||
mHandle(NULL),
|
||||
mDirty(true)
|
||||
{
|
||||
set(val);
|
||||
}
|
||||
|
||||
EffectConst(const String &name, const MatrixF &val)
|
||||
: mName(name),
|
||||
mHandle(NULL),
|
||||
mDirty(true)
|
||||
{
|
||||
set(val);
|
||||
}
|
||||
|
||||
EffectConst(const String &name, const Vector<Point4F> &val)
|
||||
: mName(name),
|
||||
mHandle(NULL),
|
||||
mDirty(true)
|
||||
{
|
||||
set(val);
|
||||
}
|
||||
|
||||
EffectConst(const String &name, const Vector<MatrixF> &val)
|
||||
: mName(name),
|
||||
mHandle(NULL),
|
||||
mDirty(true)
|
||||
{
|
||||
set(val);
|
||||
}
|
||||
|
||||
void set( const String &newVal );
|
||||
void set(const F32 &newVal);
|
||||
void set(const Point4F &newVal);
|
||||
void set(const MatrixF &newVal);
|
||||
void set(const Vector<Point4F> &newVal);
|
||||
void set(const Vector<MatrixF> &newVal);
|
||||
|
||||
void setToBuffer( GFXShaderConstBufferRef buff );
|
||||
|
||||
|
|
@ -220,6 +277,23 @@ protected:
|
|||
|
||||
String mStringVal;
|
||||
|
||||
F32 mFloatVal;
|
||||
Point4F mPointVal;
|
||||
MatrixF mMatrixVal;
|
||||
|
||||
Vector<Point4F> mPointArrayVal;
|
||||
Vector<MatrixF> mMatrixArrayVal;
|
||||
|
||||
enum
|
||||
{
|
||||
StringType,
|
||||
FloatType,
|
||||
PointType,
|
||||
MatrixType,
|
||||
PointArrayType,
|
||||
MatrixArrayType
|
||||
} mValueType;
|
||||
|
||||
bool mDirty;
|
||||
};
|
||||
|
||||
|
|
@ -245,6 +319,9 @@ protected:
|
|||
|
||||
///
|
||||
virtual void _setupTexture( U32 slot, GFXTexHandle &inputTex, const RectI *inTexViewport );
|
||||
virtual void _setupCubemapTexture(U32 stage, GFXCubemapHandle &inputTex);
|
||||
virtual void _setupCubemapArrayTexture(U32 slot, GFXCubemapArrayHandle &inputTex);
|
||||
|
||||
|
||||
/// Protected set method for toggling the enabled state.
|
||||
static bool _setIsEnabled( void *object, const char *index, const char *data );
|
||||
|
|
@ -339,6 +416,8 @@ public:
|
|||
F32 getPriority() const { return mRenderPriority; }
|
||||
|
||||
void setTexture( U32 index, const String &filePath );
|
||||
void setCubemapTexture(U32 index, const GFXCubemapHandle &cubemapHandle);
|
||||
void setCubemapArrayTexture(U32 index, const GFXCubemapArrayHandle &cubemapArrayHandle);
|
||||
|
||||
void setShaderMacro( const String &name, const String &value = String::EmptyString );
|
||||
bool removeShaderMacro( const String &name );
|
||||
|
|
@ -346,6 +425,11 @@ public:
|
|||
|
||||
///
|
||||
void setShaderConst( const String &name, const String &val );
|
||||
void setShaderConst(const String &name, const F32 &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);
|
||||
void setShaderConst(const String &name, const Vector<MatrixF> &val);
|
||||
|
||||
void setOnThisFrame( bool enabled ) { mOnThisFrame = enabled; }
|
||||
bool isOnThisFrame() { return mOnThisFrame; }
|
||||
|
|
|
|||
|
|
@ -249,33 +249,6 @@ RenderProbeMgr::RenderProbeMgr()
|
|||
String brdfPath = Con::getVariable("$Core::BRDFTexture", "core/art/pbr/brdfTexture.dds");
|
||||
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);
|
||||
|
||||
probePositions.setSize(MAXPROBECOUNT);
|
||||
probePositions.fill(Point3F::Zero);
|
||||
|
||||
probeWorldToObj.setSize(MAXPROBECOUNT);
|
||||
probeWorldToObj.fill(MatrixF::Identity);
|
||||
|
||||
probeBBMin.setSize(MAXPROBECOUNT);
|
||||
probeBBMin.fill(Point3F::Zero);
|
||||
|
||||
probeBBMax.setSize(MAXPROBECOUNT);
|
||||
probeBBMax.fill(Point3F::Zero);
|
||||
|
||||
probeUseSphereMode.setSize(MAXPROBECOUNT);
|
||||
probeUseSphereMode.fill(0.0f);
|
||||
|
||||
probeRadius.setSize(MAXPROBECOUNT);
|
||||
probeRadius.fill(0.0f);
|
||||
|
||||
probeAttenuation.setSize(MAXPROBECOUNT);
|
||||
probeAttenuation.fill(0.0f);
|
||||
|
||||
cubeMaps.setSize(MAXPROBECOUNT);
|
||||
cubeMaps.fill(NULL);
|
||||
|
||||
irradMaps.setSize(MAXPROBECOUNT);
|
||||
irradMaps.fill(NULL);
|
||||
|
||||
mEffectiveProbeCount = 0;
|
||||
|
||||
mProbeArrayEffect = nullptr;
|
||||
|
|
@ -363,28 +336,22 @@ PostEffect* RenderProbeMgr::getProbeArrayEffect()
|
|||
|
||||
void RenderProbeMgr::_setupStaticParameters()
|
||||
{
|
||||
mLastShader = mProbeArrayEffect->getShader();
|
||||
|
||||
if (mLastShader == nullptr)
|
||||
return;
|
||||
|
||||
mLastConstants = mLastShader->allocConstBuffer();
|
||||
|
||||
numProbesSC = mLastShader->getShaderConstHandle("$numProbes");
|
||||
|
||||
probePositionSC = mLastShader->getShaderConstHandle("$inProbePosArray");
|
||||
probeWorldToObjSC = mLastShader->getShaderConstHandle("$worldToObjArray");
|
||||
probeBBMinSC = mLastShader->getShaderConstHandle("$bbMinArray");
|
||||
probeBBMaxSC = mLastShader->getShaderConstHandle("$bbMaxArray");
|
||||
probeUseSphereModeSC = mLastShader->getShaderConstHandle("$useSphereMode");
|
||||
probeRadiusSC = mLastShader->getShaderConstHandle("$radius");
|
||||
probeAttenuationSC = mLastShader->getShaderConstHandle("$attenuation");
|
||||
|
||||
//Array rendering
|
||||
U32 probeCount = ProbeRenderInst::all.size();
|
||||
|
||||
mEffectiveProbeCount = 0;
|
||||
|
||||
probePositions.setSize(MAXPROBECOUNT);
|
||||
probeWorldToObj.setSize(MAXPROBECOUNT);
|
||||
probeBBMin.setSize(MAXPROBECOUNT);
|
||||
probeBBMax.setSize(MAXPROBECOUNT);
|
||||
probeUseSphereMode.setSize(MAXPROBECOUNT);
|
||||
probeRadius.setSize(MAXPROBECOUNT);
|
||||
probeAttenuation.setSize(MAXPROBECOUNT);
|
||||
|
||||
cubeMaps.setSize(MAXPROBECOUNT);
|
||||
irradMaps.setSize(MAXPROBECOUNT);
|
||||
|
||||
for (U32 i = 0; i < probeCount; i++)
|
||||
{
|
||||
if (mEffectiveProbeCount >= MAXPROBECOUNT)
|
||||
|
|
@ -415,10 +382,10 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
probeBBMin[i] = curEntry->mBounds.minExtents;
|
||||
probeBBMax[i] = curEntry->mBounds.maxExtents;
|
||||
|
||||
probeUseSphereMode[i] = curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0;
|
||||
probeUseSphereMode[i] = Point4F(curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0, 0,0,0);
|
||||
|
||||
probeRadius[i] = curEntry->mRadius;
|
||||
probeAttenuation[i] = 1;
|
||||
probeRadius[i] = Point4F(curEntry->mRadius,0,0,0);
|
||||
probeAttenuation[i] = Point4F(1, 0, 0, 0);
|
||||
|
||||
cubeMaps[i] = curEntry->mCubemap;
|
||||
irradMaps[i] = curEntry->mIrradianceCubemap;
|
||||
|
|
@ -433,44 +400,6 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
|
||||
mCubemapArray->initStatic(cubeMaps.address(), mEffectiveProbeCount);
|
||||
mIrradArray->initStatic(irradMaps.address(), mEffectiveProbeCount);
|
||||
|
||||
/*NamedTexTarget *deferredTarget = NamedTexTarget::find(RenderDeferredMgr::BufferName);
|
||||
if (deferredTarget)
|
||||
GFX->setTexture(0, deferredTarget->getTexture());
|
||||
else
|
||||
GFX->setTexture(0, NULL);
|
||||
|
||||
NamedTexTarget *colorTarget = NamedTexTarget::find(RenderDeferredMgr::ColorBufferName);
|
||||
if (colorTarget)
|
||||
GFX->setTexture(1, colorTarget->getTexture());
|
||||
else
|
||||
GFX->setTexture(1, NULL);
|
||||
|
||||
NamedTexTarget *matinfoTarget = NamedTexTarget::find(RenderDeferredMgr::MatInfoBufferName);
|
||||
if (matinfoTarget)
|
||||
GFX->setTexture(2, matinfoTarget->getTexture());
|
||||
else
|
||||
GFX->setTexture(2, NULL);
|
||||
|
||||
if (mBrdfTexture)
|
||||
{
|
||||
GFX->setTexture(3, mBrdfTexture);
|
||||
}
|
||||
else
|
||||
GFX->setTexture(3, NULL);*/
|
||||
|
||||
//GFX->setCubeArrayTexture(4, mCubemapArray);
|
||||
//GFX->setCubeArrayTexture(5, mIrradArray);
|
||||
|
||||
ProbeRenderInst* curEntry = ProbeRenderInst::all[0];
|
||||
//count = MAXPROBECOUNT;
|
||||
//Final packing
|
||||
mProbePositions = AlignedArray<Point4F>(mEffectiveProbeCount, sizeof(Point4F), (U8*)probePositions.address(), false);
|
||||
mProbeBBMin = AlignedArray<Point4F>(mEffectiveProbeCount, sizeof(Point4F), (U8*)probeBBMin.address(), false);
|
||||
mProbeBBMax = AlignedArray<Point4F>(mEffectiveProbeCount, sizeof(Point4F), (U8*)probeBBMax.address(), false);
|
||||
mProbeUseSphereMode = AlignedArray<float>(mEffectiveProbeCount, sizeof(float), (U8*)probeUseSphereMode.address(), false);
|
||||
mProbeRadius = AlignedArray<float>(mEffectiveProbeCount, sizeof(float), (U8*)probeRadius.address(), false);
|
||||
mProbeAttenuation = AlignedArray<float>(mEffectiveProbeCount, sizeof(float), (U8*)probeAttenuation.address(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -788,7 +717,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
|
||||
// If this is a non-diffuse pass or we have no objects to
|
||||
// render then tell the effect to skip rendering.
|
||||
if (!state->isDiffusePass()/* || binSize == 0*/|| !numProbesSC || !numProbesSC->isValid())
|
||||
if (!state->isDiffusePass()/* || binSize == 0*/)
|
||||
{
|
||||
getProbeArrayEffect()->setSkip(true);
|
||||
return;
|
||||
|
|
@ -821,30 +750,29 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
else
|
||||
GFX->setTexture(2, NULL);*/
|
||||
|
||||
if (mBrdfTexture)
|
||||
/*if (mBrdfTexture)
|
||||
{
|
||||
GFX->setTexture(3, mBrdfTexture);
|
||||
}
|
||||
else
|
||||
GFX->setTexture(3, NULL);
|
||||
GFX->setTexture(3, NULL);*/
|
||||
|
||||
GFX->setCubeArrayTexture(4, mCubemapArray);
|
||||
GFX->setCubeArrayTexture(5, mIrradArray);
|
||||
//GFX->setCubeArrayTexture(4, mCubemapArray);
|
||||
//GFX->setCubeArrayTexture(5, mIrradArray);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(4, mCubemapArray);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradArray);
|
||||
|
||||
if (numProbesSC->isValid())
|
||||
{
|
||||
mLastConstants->set(numProbesSC, (float)mEffectiveProbeCount);
|
||||
|
||||
mLastConstants->set(probePositionSC, mProbePositions);
|
||||
|
||||
mLastConstants->set(probePositionSC, mProbePositions);
|
||||
mLastConstants->set(probeWorldToObjSC, probeWorldToObj.address(), mEffectiveProbeCount);
|
||||
mLastConstants->set(probeBBMinSC, mProbeBBMin);
|
||||
mLastConstants->set(probeBBMaxSC, mProbeBBMax);
|
||||
mLastConstants->set(probeUseSphereModeSC, mProbeUseSphereMode);
|
||||
mLastConstants->set(probeRadiusSC, mProbeRadius);
|
||||
mLastConstants->set(probeAttenuationSC, mProbeAttenuation);
|
||||
}
|
||||
U32 mips = ProbeRenderInst::all[0]->mCubemap.getPointer()->getMipMapLevels();
|
||||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mips);
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
||||
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositions);
|
||||
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObj);
|
||||
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMin);
|
||||
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMax);
|
||||
mProbeArrayEffect->setShaderConst("$useSphereMode", probeUseSphereMode);
|
||||
mProbeArrayEffect->setShaderConst("$radius", probeRadius);
|
||||
mProbeArrayEffect->setShaderConst("$attenuation", probeAttenuation);
|
||||
}
|
||||
|
||||
// Finish up.
|
||||
|
|
|
|||
|
|
@ -233,17 +233,6 @@ class RenderProbeMgr : public RenderBinManager
|
|||
|
||||
MaterialParameterHandle *probeCount;
|
||||
|
||||
//
|
||||
MaterialParameterHandle *numProbesSC;
|
||||
|
||||
MaterialParameterHandle *probePositionSC;
|
||||
MaterialParameterHandle *probeWorldToObjSC;
|
||||
MaterialParameterHandle *probeBBMinSC;
|
||||
MaterialParameterHandle *probeBBMaxSC;
|
||||
MaterialParameterHandle *probeUseSphereModeSC;
|
||||
MaterialParameterHandle *probeRadiusSC;
|
||||
MaterialParameterHandle *probeAttenuationSC;
|
||||
|
||||
ReflectProbeMaterialInfo(const String &matName, const GFXVertexFormat *vertexFormat);
|
||||
|
||||
virtual ~ReflectProbeMaterialInfo();
|
||||
|
|
@ -317,13 +306,13 @@ protected:
|
|||
|
||||
//Array rendering
|
||||
U32 mEffectiveProbeCount;
|
||||
Vector<Point3F> probePositions;
|
||||
Vector<Point4F> probePositions;
|
||||
Vector<MatrixF> probeWorldToObj;
|
||||
Vector<Point3F> probeBBMin;
|
||||
Vector<Point3F> probeBBMax;
|
||||
Vector<float> probeUseSphereMode;
|
||||
Vector<float> probeRadius;
|
||||
Vector<float> probeAttenuation;
|
||||
Vector<Point4F> probeBBMin;
|
||||
Vector<Point4F> probeBBMax;
|
||||
Vector<Point4F> probeUseSphereMode;
|
||||
Vector<Point4F> probeRadius;
|
||||
Vector<Point4F> probeAttenuation;
|
||||
Vector<GFXCubemapHandle> cubeMaps;
|
||||
Vector<GFXCubemapHandle> irradMaps;
|
||||
|
||||
|
|
|
|||
|
|
@ -503,9 +503,9 @@ singleton PostEffect( reflectionProbeArrayPostFX )
|
|||
texture[0] = "#deferred";
|
||||
texture[1] = "#color";
|
||||
texture[2] = "#matinfo";
|
||||
texture[3] = "$BRDFTexture";
|
||||
texture[4] = "$cubeMap";
|
||||
texture[5] = "$irradianceCubemap";
|
||||
texture[3] = "core/art/pbr/brdfTexture.dds";
|
||||
//texture[4] = "$cubeMap";
|
||||
//texture[5] = "$irradianceCubemap";
|
||||
|
||||
target = "AL_FormatToken";
|
||||
};
|
||||
|
|
@ -18,17 +18,17 @@ uniform float cubeMips;
|
|||
#define MAX_PROBES 50
|
||||
|
||||
uniform float numProbes;
|
||||
//TORQUE_UNIFORM_SAMPLERCUBEARRAY(cubeMapAR, 4);
|
||||
//TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
|
||||
TORQUE_UNIFORM_SAMPLERCUBE(cubeMapAR, 4);
|
||||
TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemapAR, 5);
|
||||
TORQUE_UNIFORM_SAMPLERCUBEARRAY(cubeMapAR, 4);
|
||||
TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
|
||||
//TORQUE_UNIFORM_SAMPLERCUBE(cubeMapAR, 4);
|
||||
//TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemapAR, 5);
|
||||
uniform float4 inProbePosArray[MAX_PROBES];
|
||||
uniform float4x4 worldToObjArray[MAX_PROBES];
|
||||
uniform float4 bbMinArray[MAX_PROBES];
|
||||
uniform float4 bbMaxArray[MAX_PROBES];
|
||||
uniform float useSphereMode[MAX_PROBES];
|
||||
uniform float radius[MAX_PROBES];
|
||||
uniform float2 attenuation[MAX_PROBES];
|
||||
uniform float4 useSphereMode[MAX_PROBES];
|
||||
uniform float4 radius[MAX_PROBES];
|
||||
uniform float4 attenuation[MAX_PROBES];
|
||||
|
||||
// Box Projected IBL Lighting
|
||||
// Based on: http://www.gamedev.net/topic/568829-box-projected-cubemap-environment-mapping/
|
||||
|
|
@ -51,8 +51,8 @@ float3 iblBoxDiffuse( Surface surface, int id)
|
|||
{
|
||||
float3 cubeN = boxProject(surface.P, surface.N, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
cubeN.z *=-1;
|
||||
//return TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR,cubeN,id,0).xyz;
|
||||
return TORQUE_TEXCUBELOD(irradianceCubemapAR,float4(cubeN,0)).xyz;
|
||||
return TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR,cubeN,id,0).xyz;
|
||||
//return TORQUE_TEXCUBELOD(irradianceCubemapAR,float4(cubeN,0)).xyz;
|
||||
}
|
||||
|
||||
float3 iblBoxSpecular(Surface surface, float3 surfToEye, TORQUE_SAMPLER2D(brdfTexture), int id)
|
||||
|
|
@ -68,8 +68,8 @@ float3 iblBoxSpecular(Surface surface, float3 surfToEye, TORQUE_SAMPLER2D(brdfTe
|
|||
float3 cubeR = normalize(r);
|
||||
cubeR = boxProject(surface.P, surface.N, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
|
||||
//float3 radiance = TORQUE_TEXCUBEARRAYLOD(cubeMapAR,cubeR,id,lod).xyz * (brdf.x + brdf.y);
|
||||
float3 radiance = TORQUE_TEXCUBELOD(cubeMapAR,float4(cubeR,lod)).xyz * (brdf.x + brdf.y);
|
||||
float3 radiance = TORQUE_TEXCUBEARRAYLOD(cubeMapAR,cubeR,id,lod).xyz * (brdf.x + brdf.y);
|
||||
//float3 radiance = TORQUE_TEXCUBELOD(cubeMapAR,float4(cubeR,lod)).xyz * (brdf.x + brdf.y);
|
||||
|
||||
return radiance;
|
||||
}
|
||||
|
|
@ -79,8 +79,8 @@ float defineBoxSpaceInfluence(Surface surface, int id)
|
|||
float tempAttenVal = 3.5; //replace with per probe atten
|
||||
float3 surfPosLS = mul( worldToObjArray[id], float4(surface.P,1.0)).xyz;
|
||||
|
||||
float3 boxMinLS = inProbePosArray[id].xyz-(float3(1,1,1)*radius[0]);
|
||||
float3 boxMaxLS = inProbePosArray[id].xyz+(float3(1,1,1)*radius[0]);
|
||||
float3 boxMinLS = inProbePosArray[id].xyz-(float3(1,1,1)*radius[0].x);
|
||||
float3 boxMaxLS = inProbePosArray[id].xyz+(float3(1,1,1)*radius[0].x);
|
||||
|
||||
float boxOuterRange = length(boxMaxLS - boxMinLS);
|
||||
float boxInnerRange = boxOuterRange / tempAttenVal;
|
||||
|
|
@ -147,7 +147,7 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
|
|||
|
||||
float finalSum = blendSum;
|
||||
|
||||
return TORQUE_TEX2D(colorBuffer, IN.uv0.xy);
|
||||
//return TORQUE_TEX2D(colorBuffer, IN.uv0.xy);
|
||||
//return float4(surface.N,1);
|
||||
//return float4(1,1,1, 1);
|
||||
//return float4(finalSum,finalSum,finalSum, 1);
|
||||
|
|
@ -155,7 +155,7 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
|
|||
// Normalize blendVal
|
||||
if (blendSum == 0.0f) // Possible with custom weight
|
||||
{
|
||||
blendSum = 1.0f;
|
||||
//blendSum = 1.0f;
|
||||
}
|
||||
|
||||
float invBlendSumWeighted = 1.0f / blendSum;
|
||||
|
|
|
|||
Loading…
Reference in a new issue