mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 16:14:38 +00:00
Merge pull request #855 from Azaezel/cubemappedStatics
Dynamic cubemap support for tsStatics
This commit is contained in:
commit
2d76bdc8e1
3 changed files with 81 additions and 0 deletions
|
|
@ -91,6 +91,9 @@ ConsoleDocClass( TSStatic,
|
||||||
);
|
);
|
||||||
|
|
||||||
TSStatic::TSStatic()
|
TSStatic::TSStatic()
|
||||||
|
:
|
||||||
|
cubeDescId( 0 ),
|
||||||
|
reflectorDesc( NULL )
|
||||||
{
|
{
|
||||||
mNetFlags.set(Ghostable | ScopeAlways);
|
mNetFlags.set(Ghostable | ScopeAlways);
|
||||||
|
|
||||||
|
|
@ -186,6 +189,11 @@ void TSStatic::initPersistFields()
|
||||||
|
|
||||||
endGroup("Rendering");
|
endGroup("Rendering");
|
||||||
|
|
||||||
|
addGroup( "Reflection" );
|
||||||
|
addField( "cubeReflectorDesc", TypeRealString, Offset( cubeDescName, TSStatic ),
|
||||||
|
"References a ReflectorDesc datablock that defines performance and quality properties for dynamic reflections.\n");
|
||||||
|
endGroup( "Reflection" );
|
||||||
|
|
||||||
addGroup("Collision");
|
addGroup("Collision");
|
||||||
|
|
||||||
addField( "collisionType", TypeTSMeshType, Offset( mCollisionType, TSStatic ),
|
addField( "collisionType", TypeTSMeshType, Offset( mCollisionType, TSStatic ),
|
||||||
|
|
@ -292,6 +300,14 @@ bool TSStatic::onAdd()
|
||||||
|
|
||||||
addToScene();
|
addToScene();
|
||||||
|
|
||||||
|
if ( isClientObject() )
|
||||||
|
{
|
||||||
|
mCubeReflector.unregisterReflector();
|
||||||
|
|
||||||
|
if ( reflectorDesc )
|
||||||
|
mCubeReflector.registerReflector( this, reflectorDesc );
|
||||||
|
}
|
||||||
|
|
||||||
_updateShouldTick();
|
_updateShouldTick();
|
||||||
|
|
||||||
// Accumulation
|
// Accumulation
|
||||||
|
|
@ -357,6 +373,16 @@ bool TSStatic::_createShape()
|
||||||
if ( mAmbientThread )
|
if ( mAmbientThread )
|
||||||
mShapeInstance->setSequence( mAmbientThread, ambientSeq, 0);
|
mShapeInstance->setSequence( mAmbientThread, ambientSeq, 0);
|
||||||
|
|
||||||
|
// Resolve CubeReflectorDesc.
|
||||||
|
if ( cubeDescName.isNotEmpty() )
|
||||||
|
{
|
||||||
|
Sim::findObject( cubeDescName, reflectorDesc );
|
||||||
|
}
|
||||||
|
else if( cubeDescId > 0 )
|
||||||
|
{
|
||||||
|
Sim::findObject( cubeDescId, reflectorDesc );
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -429,6 +455,8 @@ void TSStatic::onRemove()
|
||||||
mShapeInstance = NULL;
|
mShapeInstance = NULL;
|
||||||
|
|
||||||
mAmbientThread = NULL;
|
mAmbientThread = NULL;
|
||||||
|
if ( isClientObject() )
|
||||||
|
mCubeReflector.unregisterReflector();
|
||||||
|
|
||||||
Parent::onRemove();
|
Parent::onRemove();
|
||||||
}
|
}
|
||||||
|
|
@ -561,6 +589,12 @@ void TSStatic::prepRenderImage( SceneRenderState* state )
|
||||||
|
|
||||||
F32 invScale = (1.0f/getMax(getMax(mObjScale.x,mObjScale.y),mObjScale.z));
|
F32 invScale = (1.0f/getMax(getMax(mObjScale.x,mObjScale.y),mObjScale.z));
|
||||||
|
|
||||||
|
// If we're currently rendering our own reflection we
|
||||||
|
// don't want to render ourselves into it.
|
||||||
|
if ( mCubeReflector.isRendering() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
if ( mForceDetail == -1 )
|
if ( mForceDetail == -1 )
|
||||||
mShapeInstance->setDetailFromDistance( state, dist * invScale );
|
mShapeInstance->setDetailFromDistance( state, dist * invScale );
|
||||||
else
|
else
|
||||||
|
|
@ -577,6 +611,9 @@ void TSStatic::prepRenderImage( SceneRenderState* state )
|
||||||
rdata.setFadeOverride( 1.0f );
|
rdata.setFadeOverride( 1.0f );
|
||||||
rdata.setOriginSort( mUseOriginSort );
|
rdata.setOriginSort( mUseOriginSort );
|
||||||
|
|
||||||
|
if ( mCubeReflector.isEnabled() )
|
||||||
|
rdata.setCubemap( mCubeReflector.getCubemap() );
|
||||||
|
|
||||||
// Acculumation
|
// Acculumation
|
||||||
rdata.setAccuTex(mAccuTex);
|
rdata.setAccuTex(mAccuTex);
|
||||||
|
|
||||||
|
|
@ -604,6 +641,20 @@ void TSStatic::prepRenderImage( SceneRenderState* state )
|
||||||
mat.scale( mObjScale );
|
mat.scale( mObjScale );
|
||||||
GFX->setWorldMatrix( mat );
|
GFX->setWorldMatrix( mat );
|
||||||
|
|
||||||
|
if ( state->isDiffusePass() && mCubeReflector.isEnabled() && mCubeReflector.getOcclusionQuery() )
|
||||||
|
{
|
||||||
|
RenderPassManager *pass = state->getRenderPass();
|
||||||
|
OccluderRenderInst *ri = pass->allocInst<OccluderRenderInst>();
|
||||||
|
|
||||||
|
ri->type = RenderPassManager::RIT_Occluder;
|
||||||
|
ri->query = mCubeReflector.getOcclusionQuery();
|
||||||
|
mObjToWorld.mulP( mObjBox.getCenter(), &ri->position );
|
||||||
|
ri->scale.set( mObjBox.getExtents() );
|
||||||
|
ri->orientation = pass->allocUniqueXform( mObjToWorld );
|
||||||
|
ri->isSphere = false;
|
||||||
|
state->getRenderPass()->addInst( ri );
|
||||||
|
}
|
||||||
|
|
||||||
mShapeInstance->animate();
|
mShapeInstance->animate();
|
||||||
if(mShapeInstance)
|
if(mShapeInstance)
|
||||||
{
|
{
|
||||||
|
|
@ -715,6 +766,10 @@ U32 TSStatic::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
||||||
if ( mLightPlugin )
|
if ( mLightPlugin )
|
||||||
retMask |= mLightPlugin->packUpdate(this, AdvancedStaticOptionsMask, con, mask, stream);
|
retMask |= mLightPlugin->packUpdate(this, AdvancedStaticOptionsMask, con, mask, stream);
|
||||||
|
|
||||||
|
if( stream->writeFlag( reflectorDesc != NULL ) )
|
||||||
|
{
|
||||||
|
stream->writeRangedU32( reflectorDesc->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast );
|
||||||
|
}
|
||||||
return retMask;
|
return retMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -782,6 +837,11 @@ void TSStatic::unpackUpdate(NetConnection *con, BitStream *stream)
|
||||||
mLightPlugin->unpackUpdate(this, con, stream);
|
mLightPlugin->unpackUpdate(this, con, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( stream->readFlag() )
|
||||||
|
{
|
||||||
|
cubeDescId = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );
|
||||||
|
}
|
||||||
|
|
||||||
if ( isProperlyAdded() )
|
if ( isProperlyAdded() )
|
||||||
_updateShouldTick();
|
_updateShouldTick();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,10 @@
|
||||||
#include "ts/tsShape.h"
|
#include "ts/tsShape.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _REFLECTOR_H_
|
||||||
|
#include "scene/reflector.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
class TSShapeInstance;
|
class TSShapeInstance;
|
||||||
class TSThread;
|
class TSThread;
|
||||||
class TSStatic;
|
class TSStatic;
|
||||||
|
|
@ -147,6 +151,11 @@ protected:
|
||||||
/// Start or stop processing ticks depending on our state.
|
/// Start or stop processing ticks depending on our state.
|
||||||
void _updateShouldTick();
|
void _updateShouldTick();
|
||||||
|
|
||||||
|
String cubeDescName;
|
||||||
|
U32 cubeDescId;
|
||||||
|
ReflectorDesc *reflectorDesc;
|
||||||
|
CubeReflector mCubeReflector;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Convex *mConvexList;
|
Convex *mConvexList;
|
||||||
|
|
|
||||||
|
|
@ -84,3 +84,15 @@ datablock LightningData(DefaultStorm)
|
||||||
thunderSounds[2] = ThunderCrash3Sound;
|
thunderSounds[2] = ThunderCrash3Sound;
|
||||||
thunderSounds[3] = ThunderCrash4Sound;
|
thunderSounds[3] = ThunderCrash4Sound;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
datablock ReflectorDesc( DefaultCubeDesc )
|
||||||
|
{
|
||||||
|
texSize = 256;
|
||||||
|
nearDist = 0.1;
|
||||||
|
farDist = 1000.0;
|
||||||
|
objectTypeMask = 0xFFFFFFFF;
|
||||||
|
detailAdjust = 1.0;
|
||||||
|
priority = 1.0;
|
||||||
|
maxRateMs = 15;
|
||||||
|
useOcclusionQuery = true;
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue