Sign in to follow this  
OuncleJulien

Shader problem

Recommended Posts

I'm writing a vertex shader for a skeletal animation I'm writing. I've written an exporter for 3dsmax that exports position, normal, tex coords, boneids[4], weights[4]. The shader compiles fine but will crash the program if I try to access the weights variable inside the shader (see commented line below). I've been racking my brain on this for hours and felt it was time to get some more eyes on the code. Can anyone see why it would crash? Whoever sees what's wrong will get a cookie! FYI- this shader just adds to the y component of the position vector if the first of 4 weights is greater than 0. This is just to test the shader. Here's my vertex struct: struct Vertex { public: D3DXVECTOR3 v; D3DXVECTOR3 n; float tu,tv; D3DXVECTOR4 boneIds; //4 bone id's D3DXVECTOR4 weights; //4 bone weights static const int FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE4(1) | D3DFVF_TEXCOORDSIZE4(2); }; Here's my decl: D3DVERTEXELEMENT9 decl[] = { {0, 0 , D3DDECLTYPE_FLOAT3 , D3DDECLMETHOD_DEFAULT , D3DDECLUSAGE_POSITION , 0}, {0, 12 , D3DDECLTYPE_FLOAT3 , D3DDECLMETHOD_DEFAULT , D3DDECLUSAGE_NORMAL , 0}, {0, 24 , D3DDECLTYPE_FLOAT2 , D3DDECLMETHOD_DEFAULT , D3DDECLUSAGE_TEXCOORD , 0}, {0, 32 , D3DDECLTYPE_FLOAT4 , D3DDECLMETHOD_DEFAULT , D3DDECLUSAGE_BLENDINDICES , 0}, {0, 48 , D3DDECLTYPE_FLOAT4 , D3DDECLMETHOD_DEFAULT , D3DDECLUSAGE_BLENDWEIGHT , 0}, D3DDECL_END() }; Here's the code: const uniform float4x4 mat; const uniform float index; void main( float4 position : POSITION, out float4 oPosition : POSITION, float3 n : NORMAL, float2 tex : TEXCOORD0, out float2 oTex : TEXCOORD0, float4 bones : TEXCOORD1, float4 weights : TEXCOORD2) { if (weights[0] > 0.0f) // This will crash the shader on both my computers one with an nvidia card and another with an ati card. If I remove the reference to weights[0] it'll run fine on both. { position.y = position.y + 20.0f; } oPosition = mul(mat,position); oTex = tex; }

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Dave Hunt
Not sure about this, but I notice your decl has position as float3, but your shader has position as float4. Maybe that's throwing it off?

Nope, it should just expand the float3 into the float4 (using 0 or 1 for the .w, don't remember)

Muhammad Haggag

Share this post


Link to post
Share on other sites
It may be the flow control that is messing you up different cards may have different support for this, the distinction between static and dynamic branching is not something I understand well. Try doing it without the 'if' like:

position.y = position.y + ( 20.0f * ceil(weights[0]));

Also note: There are semantics for blend indices and weights that might behave better than texcoords.
Using a vector4 for your blend indices will probably give you trouble (though you don't appear to be using them yet). In the DX examples they use an unsigned integer and split it into its four byte long indices.

hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this