If a matrix array with this name appears in a shader, the engine calculates the bones animation on the GPU, rather than on the CPU. This way animated actors are rendered up to 10 times faster, especially when they have many bones or bone weights.





A8  P 


// bones animation shader

#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <lights>
#include <texture>
#include <color>
float4x3 matBones[72]; int iWeights; struct vsOut { float4 Pos: POSITION; float Fog: FOG; float4 Ambient:COLOR; float2 Tex: TEXCOORD0; }; vsOut bones_VS ( in float4 inPos: POSITION, in float3 inNormal: NORMAL, in float2 inTex: TEXCOORD0, in int4 inBoneIndices: BLENDINDICES, in float4 inBoneWeights: BLENDWEIGHT ) { vsOut Out; Out.Tex = DoTexture(inTex); Out.Fog = DoFog(inPos); Out.Ambient = DoAmbient(); float3 P = DoPos(inPos); float3 N = DoNormal(inNormal); for (int i=0; i<iLights; i++) // Add 8 dynamic lights += DoLight(P,N,i)*0.5*vecDiffuse; float3 WorldPos = 0; for (int i=0; i<iWeights; i++) WorldPos += mul(inPos.xzyw,matBones[inBoneIndices[i]])*inBoneWeights[i]; Out.Pos = DoTransform(float4(WorldPos.xzy,1.0)); return Out; } technique bones { pass { VertexShader = compile vs_2_0 bones_VS(); } }

See also:

Shader variables, matTangent

► latest version online