• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

### #ActualBanderi

Posted 04 March 2013 - 03:57 PM

Now first, I'm still waaay newbie at HLSL;

I thought such a "simple" code (not many articulated functions, just a big, main one) would be technically correct, but it keeps crashing :/

//Transformation Matrices
matrix matW;
matrix matVP;

extern float4x4 MatrixPalette[35];
extern int numBoneInfluences = 2;

//Vertex Input
struct VS_INPUT_SKIN
{
float4 position : POSITION0;
float3 normal   : NORMAL;
float2 tex0     : TEXCOORD0;
float4 weights  : BLENDWEIGHT0;
int4   boneIndices : BLENDINDICES0;
};

//Vertex Output / Pixel Shader Input
struct VS_OUTPUT
{
float4 position : POSITION0;
float2 tex0     : TEXCOORD0;
};

VS_OUTPUT vs_Skinning(VS_INPUT_SKIN IN)
{
VS_OUTPUT OUT = (VS_OUTPUT)0;

float4 p = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 norm = float3(0.0f, 0.0f, 0.0f);
float lastWeight = 0.0f;
int n = numBoneInfluences-1;
IN.normal = normalize(IN.normal);

//Blend vertex position & normal
for(int i = 0; i < n; ++i)
{
lastWeight += IN.weights[i];
p += IN.weights[i] * mul(IN.position, MatrixPalette[IN.boneIndices[i]]);
norm += IN.weights[i] * mul(IN.normal, MatrixPalette[IN.boneIndices[i]]);
}
lastWeight = 1.0f - lastWeight;

p += lastWeight * mul(IN.position, MatrixPalette[IN.boneIndices[n]]);
norm += lastWeight * mul(IN.normal, MatrixPalette[IN.boneIndices[n]]);
p.w = 1.0f;

//Transform vertex to world space
float4 posWorld = mul(p, matW);

//... then to screen space
OUT.position = mul(posWorld, matVP);

//Copy UV coordinate
OUT.tex0 = IN.tex0;

//Calculate Lighting
norm = normalize(norm);
norm = mul(norm, matW);
OUT.shade = max(dot(norm, normalize(lightPos - posWorld)), 0.2f);

return OUT;
}

technique Skinning
{
pass P0
{
Lighting = false;

}
}


C++ runs correctly other shader files, but with this one it crashes (0xC0000005 access violation) whenever it gets to the point where it sets the matrices for it (ID3DXEffect->SetMatrix();), no matter what matrix I choose to set first.

Is the error in the HLSL itself or is it C++ related? Do I have to post more code?

### #1Banderi

Posted 03 March 2013 - 08:07 AM

Now first, I'm still waaay newbie at HLSL;

I thought such a "simple" code (not many articulated functions, just a big, main one) would be technically correct, but it keeps crashing :/

//Transformation Matrices
matrix matW;
matrix matVP;

extern float4x4 MatrixPalette[35];
extern int numBoneInfluences = 2;

//Vertex Input
struct VS_INPUT_SKIN
{
float4 position : POSITION0;
float3 normal   : NORMAL;
float2 tex0     : TEXCOORD0;
float4 weights  : BLENDWEIGHT0;
int4   boneIndices : BLENDINDICES0;
};

//Vertex Output / Pixel Shader Input
struct VS_OUTPUT
{
float4 position : POSITION0;
float2 tex0     : TEXCOORD0;
};

VS_OUTPUT vs_Skinning(VS_INPUT_SKIN IN)
{
VS_OUTPUT OUT = (VS_OUTPUT)0;

float4 p = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 norm = float3(0.0f, 0.0f, 0.0f);
float lastWeight = 0.0f;
int n = numBoneInfluences-1;
IN.normal = normalize(IN.normal);

//Blend vertex position & normal
for(int i = 0; i < n; ++i)
{
lastWeight += IN.weights[i];
p += IN.weights[i] * mul(IN.position, MatrixPalette[IN.boneIndices[i]]);
norm += IN.weights[i] * mul(IN.normal, MatrixPalette[IN.boneIndices[i]]);
}
lastWeight = 1.0f - lastWeight;

p += lastWeight * mul(IN.position, MatrixPalette[IN.boneIndices[n]]);
norm += lastWeight * mul(IN.normal, MatrixPalette[IN.boneIndices[n]]);
p.w = 1.0f;

//Transform vertex to world space
float4 posWorld = mul(p, matW);

//... then to screen space
OUT.position = mul(posWorld, matVP);

//Copy UV coordinate
OUT.tex0 = IN.tex0;

//Calculate Lighting
norm = normalize(norm);
norm = mul(norm, matW);
OUT.shade = max(dot(norm, normalize(lightPos - posWorld)), 0.2f);

return OUT;
}

technique Skinning
{
pass P0
{
Lighting = false;

}
}


C++ runs correctly other shader files, but with this one it crashes (0xC0000005 access violation) whenever it gets to the point where it sets the matrices for it (ID3DXEffect->SetMatrix();), no matter what matrix I choose to set first.

Is the error in the HLSL itself or is it C++ related? Do I have to post more code?

PARTNERS