Jump to content

  • Log In with Google      Sign In   
  • Create Account


[SOLVED] Shader crash


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Banderi   Members   -  Reputation: 135

Like
0Likes
Like

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;
     float  shade	 : TEXCOORD1;
};

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;
		
        VertexShader = compile vs_2_0 vs_Skinning();      
    }
}

 

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?



Sponsor:

#2 Banderi   Members   -  Reputation: 135

Like
0Likes
Like

Posted 04 March 2013 - 10:44 AM

599524.jpg



#3 amrazek111   Members   -  Reputation: 692

Like
0Likes
Like

Posted 04 March 2013 - 02:27 PM

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

#4 Banderi   Members   -  Reputation: 135

Like
0Likes
Like

Posted 04 March 2013 - 03:09 PM

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, 04 March 2013 - 03:09 PM.


#5 CC Ricers   Members   -  Reputation: 623

Like
0Likes
Like

Posted 04 March 2013 - 03:45 PM

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.


My development blog: Electronic Meteor

#6 Banderi   Members   -  Reputation: 135

Like
0Likes
Like

Posted 04 March 2013 - 03:56 PM

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, 04 March 2013 - 03:58 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS