mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 14:44:36 +00:00
Hardware Skinning Support
- Supports GL, D3D9 & D3D11 - Extends vertex formats & shadergen to support blend indices and weights - Adds basic support for using 4x3 matrices for shader constants - Supports software fallback
This commit is contained in:
parent
507c239a87
commit
3496c549b5
72 changed files with 2533 additions and 1327 deletions
|
|
@ -80,6 +80,9 @@ protected:
|
|||
/// This is set by initialization and used by the prepass.
|
||||
bool mHasNormalMaps;
|
||||
|
||||
/// This material makes use of bone transforms
|
||||
bool mUsesHardwareSkinning;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~BaseMatInstance();
|
||||
|
|
@ -149,6 +152,9 @@ public:
|
|||
/// @see setupPass
|
||||
virtual void setTransforms( const MatrixSet &matrixSet, SceneRenderState *state ) = 0;
|
||||
|
||||
/// Sets node transforms for the current stage. Used for hardware skinning.
|
||||
virtual void setNodeTransforms( const MatrixF *address, const U32 numTransforms ) = 0;
|
||||
|
||||
/// This initializes various material scene state settings and
|
||||
/// should be called after setupPass() within the pass loop.
|
||||
/// @see setupPass
|
||||
|
|
@ -214,6 +220,8 @@ public:
|
|||
/// Fast test for use of normal maps in this material.
|
||||
bool hasNormalMap() const { return mHasNormalMaps; }
|
||||
|
||||
bool usesHardwareSkinning() const { return mUsesHardwareSkinning; }
|
||||
|
||||
///
|
||||
MatFeaturesDelegate& getFeaturesDelegate() { return mFeaturesDelegate; }
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "gfx/sim/cubemapData.h"
|
||||
#include "gfx/gfxCubemap.h"
|
||||
#include "core/util/safeDelete.h"
|
||||
#include "ts/tsShape.h"
|
||||
|
||||
class MatInstParameters;
|
||||
|
||||
|
|
@ -248,8 +249,10 @@ void MatInstance::construct()
|
|||
mActiveParameters = NULL;
|
||||
mDefaultParameters = NULL;
|
||||
mHasNormalMaps = false;
|
||||
mUsesHardwareSkinning = false;
|
||||
mIsForwardLit = false;
|
||||
mIsValid = false;
|
||||
mIsHardwareSkinned = false;
|
||||
|
||||
MATMGR->_track(this);
|
||||
}
|
||||
|
|
@ -360,6 +363,11 @@ bool MatInstance::processMaterial()
|
|||
|
||||
FeatureSet features( mFeatureList );
|
||||
features.exclude( MATMGR->getExclusionFeatures() );
|
||||
|
||||
if (mVertexFormat->hasBlendIndices() && TSShape::smUseHardwareSkinning)
|
||||
{
|
||||
features.addFeature( MFT_HardwareSkinning );
|
||||
}
|
||||
|
||||
if( !mProcessedMaterial->init(features, mVertexFormat, mFeaturesDelegate) )
|
||||
{
|
||||
|
|
@ -373,11 +381,14 @@ bool MatInstance::processMaterial()
|
|||
|
||||
const FeatureSet &finalFeatures = mProcessedMaterial->getFeatures();
|
||||
mHasNormalMaps = finalFeatures.hasFeature( MFT_NormalMap );
|
||||
mUsesHardwareSkinning = finalFeatures.hasFeature( MFT_HardwareSkinning );
|
||||
|
||||
mIsForwardLit = ( custMat && custMat->mForwardLit ) ||
|
||||
( !finalFeatures.hasFeature( MFT_IsEmissive ) &&
|
||||
finalFeatures.hasFeature( MFT_ForwardShading ) );
|
||||
|
||||
mIsHardwareSkinned = finalFeatures.hasFeature( MFT_HardwareSkinning );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -455,6 +466,12 @@ void MatInstance::setTransforms(const MatrixSet &matrixSet, SceneRenderState *st
|
|||
mProcessedMaterial->setTransforms(matrixSet, state, getCurPass());
|
||||
}
|
||||
|
||||
void MatInstance::setNodeTransforms(const MatrixF *address, const U32 numTransforms)
|
||||
{
|
||||
PROFILE_SCOPE(MatInstance_setNodeTransforms);
|
||||
mProcessedMaterial->setNodeTransforms(address, numTransforms, getCurPass());
|
||||
}
|
||||
|
||||
void MatInstance::setSceneInfo(SceneRenderState * state, const SceneData& sgData)
|
||||
{
|
||||
PROFILE_SCOPE(MatInstance_setSceneInfo);
|
||||
|
|
|
|||
|
|
@ -65,12 +65,14 @@ public:
|
|||
virtual MaterialParameterHandle* getMaterialParameterHandle(const String& name);
|
||||
virtual bool setupPass(SceneRenderState *, const SceneData &sgData );
|
||||
virtual void setTransforms(const MatrixSet &matrixSet, SceneRenderState *state);
|
||||
virtual void setNodeTransforms(const MatrixF *address, const U32 numTransforms);
|
||||
virtual void setSceneInfo(SceneRenderState *, const SceneData& sgData);
|
||||
virtual void setTextureStages(SceneRenderState * state, const SceneData &sgData );
|
||||
virtual void setBuffers(GFXVertexBufferHandleBase* vertBuffer, GFXPrimitiveBufferHandle* primBuffer);
|
||||
virtual bool isInstanced() const;
|
||||
virtual bool stepInstance();
|
||||
virtual bool isForwardLit() const { return mIsForwardLit; }
|
||||
virtual bool isHardwareSkinned() const { return mIsHardwareSkinned; }
|
||||
virtual void setUserObject( SimObject *userObject ) { mUserObject = userObject; }
|
||||
virtual SimObject* getUserObject() const { return mUserObject; }
|
||||
virtual Material *getMaterial() { return mMaterial; }
|
||||
|
|
@ -113,6 +115,9 @@ protected:
|
|||
/// If the processed material requires forward lighting or not.
|
||||
bool mIsForwardLit;
|
||||
|
||||
/// If the processed material requires bone transforms
|
||||
bool mIsHardwareSkinned;
|
||||
|
||||
S32 mCurPass;
|
||||
U32 mMaxStages;
|
||||
|
||||
|
|
|
|||
|
|
@ -103,3 +103,6 @@ ImplementFeatureType( MFT_DeferredEmptySpec, MFG_Texture, 8.01f, false );
|
|||
ImplementFeatureType( MFT_DeferredSpecMap, MFG_Texture, 8.2f, false );
|
||||
ImplementFeatureType( MFT_DeferredSpecVars, MFG_Texture, 8.5f, false );
|
||||
ImplementFeatureType( MFT_DeferredMatInfoFlags, MFG_Texture, 8.7f, false );
|
||||
|
||||
ImplementFeatureType( MFT_HardwareSkinning, MFG_Transform,-2.0, false );
|
||||
|
||||
|
|
|
|||
|
|
@ -179,6 +179,8 @@ DeclareFeatureType( MFT_ForwardShading );
|
|||
/// so that the rest of the material features can work on it.
|
||||
DeclareFeatureType( MFT_ImposterVert );
|
||||
|
||||
DeclareFeatureType( MFT_HardwareSkinning );
|
||||
|
||||
|
||||
// Deferred Shading
|
||||
DeclareFeatureType( MFT_isDeferred );
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@ enum RegisterType
|
|||
RT_COLOR,
|
||||
RT_TEXCOORD,
|
||||
RT_VPOS,
|
||||
RT_SVPOSITION
|
||||
RT_SVPOSITION,
|
||||
RT_BLENDINDICES,
|
||||
RT_BLENDWEIGHT
|
||||
};
|
||||
|
||||
enum Components
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ public:
|
|||
virtual MaterialParameters* getDefaultMaterialParameters();
|
||||
|
||||
virtual void setTransforms(const MatrixSet &matrixSet, SceneRenderState *state, const U32 pass);
|
||||
virtual void setNodeTransforms(const MatrixF *address, const U32 numTransforms, const U32 pass) {;}
|
||||
|
||||
virtual void setSceneInfo(SceneRenderState *, const SceneData& sgData, U32 pass);
|
||||
|
||||
|
|
|
|||
|
|
@ -142,6 +142,9 @@ public:
|
|||
/// Sets the transformation matrix, i.e. Model * View * Projection
|
||||
virtual void setTransforms(const MatrixSet &matrixSet, SceneRenderState *state, const U32 pass) = 0;
|
||||
|
||||
/// Sets the node transforms for HW Skinning
|
||||
virtual void setNodeTransforms(const MatrixF *address, const U32 numTransforms, const U32 pass) = 0;
|
||||
|
||||
/// Sets the scene info like lights for the given pass.
|
||||
virtual void setSceneInfo(SceneRenderState *, const SceneData& sgData, U32 pass) = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@
|
|||
// We need to include customMaterialDefinition for ShaderConstHandles::init
|
||||
#include "materials/customMaterialDefinition.h"
|
||||
|
||||
|
||||
#include "ts/tsShape.h"
|
||||
|
||||
///
|
||||
/// ShaderConstHandles
|
||||
///
|
||||
|
|
@ -99,6 +102,9 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/
|
|||
for (S32 i = 0; i < TEXTURE_STAGE_COUNT; ++i)
|
||||
mRTParamsSC[i] = shader->getShaderConstHandle( String::ToString( "$rtParams%d", i ) );
|
||||
|
||||
// MFT_HardwareSkinning
|
||||
mNodeTransforms = shader->getShaderConstHandle( "$nodeTransforms" );
|
||||
|
||||
// Clear any existing texture handles.
|
||||
dMemset( mTexHandlesSC, 0, sizeof( mTexHandlesSC ) );
|
||||
if(mat)
|
||||
|
|
@ -491,6 +497,12 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
|
|||
&fd );
|
||||
}
|
||||
|
||||
// Need to add the Hardware Skinning feature if its used
|
||||
if ( features.hasFeature( MFT_HardwareSkinning ) )
|
||||
{
|
||||
fd.features.addFeature( MFT_HardwareSkinning );
|
||||
}
|
||||
|
||||
// Now disable any features that were
|
||||
// not part of the input feature handle.
|
||||
fd.features.filter( features );
|
||||
|
|
@ -1217,6 +1229,20 @@ void ProcessedShaderMaterial::setTransforms(const MatrixSet &matrixSet, SceneRen
|
|||
shaderConsts->set( handles->m_vEyeSC, state->getVectorEye() );
|
||||
}
|
||||
|
||||
void ProcessedShaderMaterial::setNodeTransforms(const MatrixF *transforms, const U32 transformCount, const U32 pass)
|
||||
{
|
||||
PROFILE_SCOPE( ProcessedShaderMaterial_setNodeTransforms );
|
||||
|
||||
GFXShaderConstBuffer* shaderConsts = _getShaderConstBuffer(pass);
|
||||
ShaderConstHandles* handles = _getShaderConstHandles(pass);
|
||||
|
||||
if ( handles->mNodeTransforms->isValid() )
|
||||
{
|
||||
S32 realTransformCount = getMin( transformCount, TSShape::smMaxSkinBones );
|
||||
shaderConsts->set( handles->mNodeTransforms, transforms, realTransformCount, GFXSCT_Float4x3 );
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessedShaderMaterial::setSceneInfo(SceneRenderState * state, const SceneData& sgData, U32 pass)
|
||||
{
|
||||
PROFILE_SCOPE( ProcessedShaderMaterial_setSceneInfo );
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ public:
|
|||
GFXShaderConstHandle* mTexHandlesSC[Material::MAX_TEX_PER_PASS];
|
||||
GFXShaderConstHandle* mRTParamsSC[TEXTURE_STAGE_COUNT];
|
||||
|
||||
GFXShaderConstHandle* mNodeTransforms;
|
||||
|
||||
void init( GFXShader* shader, CustomMaterial* mat = NULL );
|
||||
};
|
||||
|
||||
|
|
@ -128,6 +130,7 @@ public:
|
|||
virtual bool setupPass(SceneRenderState *, const SceneData& sgData, U32 pass);
|
||||
virtual void setTextureStages(SceneRenderState *, const SceneData &sgData, U32 pass );
|
||||
virtual void setTransforms(const MatrixSet &matrixSet, SceneRenderState *state, const U32 pass);
|
||||
virtual void setNodeTransforms(const MatrixF *address, const U32 numTransforms, const U32 pass);
|
||||
virtual void setSceneInfo(SceneRenderState *, const SceneData& sgData, U32 pass);
|
||||
virtual void setBuffers(GFXVertexBufferHandleBase* vertBuffer, GFXPrimitiveBufferHandle* primBuffer);
|
||||
virtual bool stepInstance();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue