Followers 0

5 posts in this topic

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?

0

Share on other sites
It sounds like D3DXCreateEffect* might have failed and you're trying to access a NULL pointer. Did you check its return value?
0

Share on other sites

Mhh, the D3DXCreateEffectFromFile() function returns me E_FAIL..

Looking for info on this, I think I'd need to debug the HLSL.. how can I do that the simplest way?

Edited by Banderi
0

Share on other sites

Been a while since I used DX9 for compiling effects, but for this situation, doesn't the technique require both a vertex and a pixel shader? Your effect file only contains a vertex shader without a pixel shader to send the output to.

0

Share on other sites

No, I'm pretty sure I can pass just a VS or a PX alone (some HLSLs in tutorials had only this or that and worked fine);

Anyways, I added its compilation to the VC++ debugger via the official FXC compiler and it showed me that there was a variable I didn't declare XD

Now it works just fine (well, actually the rendering is all messed up, but I knew it, I was just testing)

EDIT: If it can be of help, this is how to add the compilation of an .fx file to debug HLSL: http://takinginitiative.net/2011/02/19/debugging-hlsl/

Edited by Banderi
0

Create an account

Register a new account