mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 23:24:41 +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
|
|
@ -32,7 +32,20 @@ Var * ShaderConnectorHLSL::getElement( RegisterType type,
|
|||
U32 numElements,
|
||||
U32 numRegisters )
|
||||
{
|
||||
Var *ret = getIndexedElement( mCurTexElem, type, numElements, numRegisters );
|
||||
Var *ret = NULL;
|
||||
|
||||
if ( type == RT_BLENDINDICES )
|
||||
{
|
||||
ret = getIndexedElement( mCurBlendIndicesElem, type, numElements, numRegisters );
|
||||
}
|
||||
else if ( type == RT_BLENDWEIGHT )
|
||||
{
|
||||
ret = getIndexedElement( mCurBlendWeightsElem, type, numElements, numRegisters );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = getIndexedElement( mCurTexElem, type, numElements, numRegisters );
|
||||
}
|
||||
|
||||
// Adjust texture offset if this is a texcoord type
|
||||
if( type == RT_TEXCOORD )
|
||||
|
|
@ -42,6 +55,20 @@ Var * ShaderConnectorHLSL::getElement( RegisterType type,
|
|||
else
|
||||
mCurTexElem += numElements;
|
||||
}
|
||||
else if ( type == RT_BLENDINDICES )
|
||||
{
|
||||
if ( numRegisters != -1 )
|
||||
mCurBlendIndicesElem += numRegisters;
|
||||
else
|
||||
mCurBlendIndicesElem += numElements;
|
||||
}
|
||||
else if ( type == RT_BLENDWEIGHT )
|
||||
{
|
||||
if ( numRegisters != -1 )
|
||||
mCurBlendWeightsElem += numRegisters;
|
||||
else
|
||||
mCurBlendWeightsElem += numElements;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -133,6 +160,46 @@ Var * ShaderConnectorHLSL::getIndexedElement( U32 index, RegisterType type, U32
|
|||
return newVar;
|
||||
}
|
||||
|
||||
case RT_BLENDINDICES:
|
||||
{
|
||||
Var *newVar = new Var;
|
||||
mElementList.push_back( newVar );
|
||||
|
||||
// This was needed for hardware instancing, but
|
||||
// i don't really remember why right now.
|
||||
if ( index > mCurBlendIndicesElem )
|
||||
mCurBlendIndicesElem = index + 1;
|
||||
|
||||
char out[32];
|
||||
dSprintf( (char*)out, sizeof(out), "BLENDINDICES%d", index );
|
||||
newVar->setConnectName( out );
|
||||
newVar->constNum = index;
|
||||
newVar->arraySize = numElements;
|
||||
|
||||
return newVar;
|
||||
}
|
||||
|
||||
case RT_BLENDWEIGHT:
|
||||
{
|
||||
Var *newVar = new Var;
|
||||
mElementList.push_back( newVar );
|
||||
|
||||
// This was needed for hardware instancing, but
|
||||
// i don't really remember why right now.
|
||||
if ( index > mCurBlendWeightsElem )
|
||||
mCurBlendWeightsElem = index + 1;
|
||||
|
||||
char out[32];
|
||||
dSprintf( (char*)out, sizeof(out), "BLENDWEIGHT%d", index );
|
||||
newVar->setConnectName( out );
|
||||
newVar->constNum = index;
|
||||
newVar->arraySize = numElements;
|
||||
|
||||
return newVar;
|
||||
}
|
||||
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -177,6 +244,8 @@ void ShaderConnectorHLSL::reset()
|
|||
|
||||
mElementList.setSize( 0 );
|
||||
mCurTexElem = 0;
|
||||
mCurBlendIndicesElem = 0;
|
||||
mCurBlendWeightsElem = 0;
|
||||
}
|
||||
|
||||
void ShaderConnectorHLSL::print( Stream &stream, bool isVertexShader )
|
||||
|
|
@ -231,12 +300,23 @@ void ParamsDefHLSL::assignConstantNumbers()
|
|||
if (dStrcmp((const char*)var->type, "float4x4") == 0)
|
||||
{
|
||||
mCurrConst += (4 * var->arraySize);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dStrcmp((const char*)var->type, "float3x3") == 0)
|
||||
{
|
||||
mCurrConst += (3 * var->arraySize);
|
||||
} else {
|
||||
mCurrConst += var->arraySize;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dStrcmp((const char*)var->type, "float4x3") == 0)
|
||||
{
|
||||
mCurrConst += (3 * var->arraySize);
|
||||
}
|
||||
else
|
||||
{
|
||||
mCurrConst += var->arraySize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "core/util/autoPtr.h"
|
||||
|
||||
#include "lighting/advanced/advancedLightBinManager.h"
|
||||
#include "ts/tsShape.h"
|
||||
|
||||
LangElement * ShaderFeatureHLSL::setupTexSpaceMat( Vector<ShaderComponent*> &, // componentList
|
||||
Var **texSpaceMat )
|
||||
|
|
@ -2991,3 +2992,66 @@ void ImposterVertFeatureHLSL::determineFeature( Material *material,
|
|||
outFeatureData->features.addFeature( MFT_ImposterVert );
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
// HardwareSkinningFeatureHLSL
|
||||
//****************************************************************************
|
||||
|
||||
void HardwareSkinningFeatureHLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
Var *inPosition = (Var*)LangElement::find( "inPosition" );
|
||||
Var *inNormal = (Var*)LangElement::find( "inNormal" );
|
||||
|
||||
if ( !inPosition )
|
||||
inPosition = (Var*)LangElement::find( "position" );
|
||||
|
||||
if ( !inNormal )
|
||||
inNormal = (Var*)LangElement::find( "normal" );
|
||||
|
||||
Var* posePos = new Var("posePos", "float3");
|
||||
Var* poseNormal = new Var("poseNormal", "float3");
|
||||
Var* poseMat = new Var("poseMat", "float4x3");
|
||||
Var* poseRotMat = new Var("poseRotMat", "float3x3");
|
||||
Var* nodeTransforms = (Var*)LangElement::find("nodeTransforms");
|
||||
|
||||
if (!nodeTransforms)
|
||||
{
|
||||
nodeTransforms = new Var("nodeTransforms", "float4x3");
|
||||
nodeTransforms->uniform = true;
|
||||
nodeTransforms->arraySize = TSShape::smMaxSkinBones;
|
||||
nodeTransforms->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
U32 numIndices = mVertexFormat->getNumBlendIndices();
|
||||
meta->addStatement( new GenOp( " @ = 0.0;\r\n", new DecOp( posePos ) ) );
|
||||
meta->addStatement( new GenOp( " @ = 0.0;\r\n", new DecOp( poseNormal ) ) );
|
||||
meta->addStatement( new GenOp( " @;\r\n", new DecOp( poseMat ) ) );
|
||||
meta->addStatement(new GenOp(" @;\r\n int i;\r\n", new DecOp(poseRotMat)));
|
||||
|
||||
for (U32 i=0; i<numIndices; i++)
|
||||
{
|
||||
// NOTE: To keep things simple, we assume all 4 bone indices are used in each element chunk.
|
||||
LangElement* inIndices = (Var*)LangElement::find(String::ToString( "blendIndices%d", i ));
|
||||
LangElement* inWeights = (Var*)LangElement::find(String::ToString( "blendWeight%d", i ));
|
||||
|
||||
AssertFatal(inIndices && inWeights, "Something went wrong here");
|
||||
AssertFatal(poseMat && nodeTransforms && posePos && inPosition && inWeights && poseNormal && inNormal && poseRotMat, "Something went REALLY wrong here");
|
||||
|
||||
meta->addStatement( new GenOp( " for (i=0; i<4; i++) {\r\n" ) );
|
||||
meta->addStatement( new GenOp( " int poseIdx = int(@[i]);\r\n", inIndices ) );
|
||||
meta->addStatement( new GenOp( " float poseWeight = @[i];\r\n", inWeights) );
|
||||
meta->addStatement( new GenOp( " @ = @[poseIdx];\r\n", poseMat, nodeTransforms) );
|
||||
meta->addStatement( new GenOp( " @ = (float3x3)@;\r\n", poseRotMat, poseMat) );
|
||||
meta->addStatement( new GenOp( " @ += (mul(float4(@, 1), @)).xyz * poseWeight;\r\n", posePos, inPosition, poseMat) );
|
||||
meta->addStatement( new GenOp( " @ += (mul(@,@) * poseWeight);\r\n", poseNormal, inNormal, poseRotMat) );
|
||||
meta->addStatement( new GenOp( " }\r\n" ) );
|
||||
}
|
||||
|
||||
// Assign new position and normal
|
||||
meta->addStatement( new GenOp( " @ = @;\r\n", inPosition, posePos ) );
|
||||
meta->addStatement( new GenOp( " @ = normalize(@);\r\n", inNormal, poseNormal ) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -663,4 +663,17 @@ public:
|
|||
MaterialFeatureData *outFeatureData );
|
||||
};
|
||||
|
||||
/// Hardware Skinning
|
||||
class HardwareSkinningFeatureHLSL : public ShaderFeatureHLSL
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
|
||||
virtual void processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual String getName() { return "Hardware Skinning"; }
|
||||
};
|
||||
|
||||
#endif // _SHADERGEN_HLSL_SHADERFEATUREHLSL_H_
|
||||
|
|
|
|||
|
|
@ -121,6 +121,9 @@ const char* ShaderGenComponentFactoryHLSL::typeToString( GFXDeclType type )
|
|||
case GFXDeclType_Float4:
|
||||
case GFXDeclType_Color:
|
||||
return "float4";
|
||||
|
||||
case GFXDeclType_UByte4:
|
||||
return "uint4";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,6 +177,22 @@ ShaderComponent* ShaderGenComponentFactoryHLSL::createVertexInputConnector( cons
|
|||
else
|
||||
var->setName( String::ToString( "texCoord%d", element.getSemanticIndex() + 1 ) );
|
||||
}
|
||||
else if ( element.isSemantic( GFXSemantic::BLENDINDICES ) )
|
||||
{
|
||||
var = vertComp->getIndexedElement( element.getSemanticIndex(), RT_BLENDINDICES );
|
||||
var->setName( String::ToString( "blendIndices%d", element.getSemanticIndex() ) );
|
||||
}
|
||||
else if ( element.isSemantic( GFXSemantic::BLENDWEIGHT ) )
|
||||
{
|
||||
var = vertComp->getIndexedElement( element.getSemanticIndex(), RT_BLENDWEIGHT );
|
||||
var->setName( String::ToString( "blendWeight%d", element.getSemanticIndex() ) );
|
||||
}
|
||||
else if ( element.isSemantic( GFXSemantic::PADDING ) )
|
||||
{
|
||||
var = NULL;
|
||||
//var = vertComp->getIndexedElement( vertComp->getCurTexElem() + element.getSemanticIndex(), RT_TEXCOORD );
|
||||
//var->setName( String::ToString( "pad%d", element.getSemanticIndex() + 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything else is a texcoord!
|
||||
|
|
|
|||
|
|
@ -100,13 +100,13 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
|
|||
|
||||
FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureHLSL );
|
||||
|
||||
// Deferred Shading
|
||||
FEATUREMGR->registerFeature( MFT_isDeferred, new NamedFeatureHLSL( "Deferred Material" ) );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredSpecMap, new DeferredSpecMapHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredSpecVars, new DeferredSpecVarsHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredMatInfoFlags, new DeferredMatInfoFlagsHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredEmptySpec, new DeferredEmptySpecHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureHLSL( "skybox" ) );
|
||||
FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureHLSL );
|
||||
}
|
||||
|
||||
MODULE_BEGIN( ShaderGenHLSL )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue