My vertex shader is as follows:
Code: Select all
void main_vp
(
float4 iPosition : POSITION,
float3 iNormal : NORMAL,
float4 iTexCoord0 : TEXCOORD0,
float4 iColor : COLOR0,
float4 BlendIdx : BLENDINDICES,
float4 BlendWgt : BLENDWEIGHT,
out float4 oPosition : POSITION,
out float4 oTexCoord0 : TEXCOORD0,
out float3 oNormal : TEXCOORD1,
out float4 oShadowLightspacePos : TEXCOORD2,
uniform float4x4 viewProjMatrix,
uniform float3x4 worldMatrix3x4Array[80],
uniform float4x4 worldViewProj,
uniform float4x4 worldMat,
uniform float4x4 texMatrix0
)
{
float4 blendPos = float4(0,0,0,0);
int i;
for (i = 0; i < 3; ++i)
{
blendPos += float4(mul(worldMatrix3x4Array[BlendIdx[i]], iPosition).xyz, 1.0) * BlendWgt[i];
}
oPosition = mul(viewProjMatrix, blendPos);
oTexCoord0 = iTexCoord0;
oNormal = normalize(mul(float3x3(worldMat), iNormal));
float3 newnormal = float3(0,0,0);
for (i = 0; i < 3; ++i)
{
newnormal += mul((float3x3)worldMatrix3x4Array[BlendIdx[i]], iNormal) * BlendWgt[i];
}
oNormal = newnormal;
oShadowLightspacePos = mul(texMatrix0, blendPos);
oTexCoord0.z = oPosition.z;
}
It seems to occur at random (most of the time the model is displayed correctly, sometimes with artefacts, and sometimes not at all - but the shadow is still projected), I haven't been able to track down the issue yet.
Edit: Here's a rare one with the model being invisible: http://i.imgur.com/rormops.jpg