Jump to content
  • Advertisement
Sign in to follow this  
RetroBilly

Why does this work in HLSL but not CG?

This topic is 2608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get my old HLSL shader converted to CG but the compiler is crashing in a very odd location. When I try to use mul on a matrix more than twice the shader will not compile. Here is my shader:



struct VS_INPUT
{
float3 pos : POSITION;
float3 norm : NORMAL;
float2 tex : TEXCOORD0;
float4 bw : TEXCOORD1;
float4 bi : TEXCOORD2;
};

struct VS_OUTPUT {
float4 pos : POSITION;
float3 color : COLOR;
};

float4x4 World : WORLD;
float4x4 View : WORLDVIEW;
float4x4 Proj : PROJECTION;
float4x4 Bones[255] : BONEARRAY;

VS_OUTPUT VS( VS_INPUT In )
{
VS_OUTPUT Out;
float4x4 skinTransform = 0;
float3x3 normTransform = 0;
skinTransform += Bones[In.bi.x] * In.bw.x;
skinTransform += Bones[In.bi.y] * In.bw.y;
skinTransform += Bones[In.bi.z] * In.bw.z;
skinTransform += Bones[In.bi.w] * In.bw.w;
normTransform += (float3x3)(Bones[In.bi.x] * In.bw.x);
normTransform += (float3x3)(Bones[In.bi.y] * In.bw.y);
normTransform += (float3x3)(Bones[In.bi.z] * In.bw.z);
normTransform += (float3x3)(Bones[In.bi.w] * In.bw.w);
Out.pos = mul(float4(In.pos, 1), skinTransform);
Out.pos = mul(Out.pos, View);
Out.pos = mul(Out.pos, Proj);
Out.color = float3(0,1,0);
return Out;
}




This will not compile unless I remove either line "Out.pos = mul(Out.pos, View);" or "Out.pos = mul(Out.pos, Proj);" Can someone tell me why it won't compile and how to fix it?blink.gif

Share this post


Link to post
Share on other sites
Advertisement
If the compiler is crashing then it's not really your fault -- there's a bug in the compiler.

When I ran it through my Cg compiler it refused to compile because your Bones array is too big (VS3.0 is only guaranteed to have space for 256 cregisters - your shader requires 1032 cregisters). When I reduced that array to a sensible size, it compiled fine.

On a side-note though, it's bad style to multiply by view and proj separately like that in your shaders. You should multiply view and proj on the CPU-side and upload the result as ViewProj.

Share this post


Link to post
Share on other sites

If the compiler is crashing then it's not really your fault -- there's a bug in the compiler.

When I ran it through my Cg compiler it refused to compile because your Bones array is too big (VS3.0 is only guaranteed to have space for 256 cregisters - your shader requires 1032 cregisters). When I reduced that array to a sensible size, it compiled fine.

On a side-note though, it's bad style to multiply by view and proj separately like that in your shaders. You should multiply view and proj on the CPU-side and upload the result as ViewProj.


Thanks for your reply, Hodgman, by reducing it I was able to get it to compile but it would not render anything. I messed around with it and believe the real problem is in the way I am inputing the vertex data. I changed the tags at the end of each variable and was able to get it to compile and render without even changing the size of the bone array. Here is what I did:



struct VS_INPUT
{
float3 pos : POSITION;
float3 norm : NORMAL;
float2 tex : TEXCOORD0;
float4 bw : COLOR0;
float4 bi : COLOR1;
};



Now this appears to be fully functional but I really don't understand how to properly do this. I am injecting the vertices like this:



glVertexAttribPointerARB( 0, 3, GL_FLOAT, GL_FALSE, sizeof(Ovgl::Vertex), ((char *)NULL + (0)) );
glVertexAttribPointerARB( 1, 3, GL_FLOAT, GL_FALSE, sizeof(Ovgl::Vertex), ((char *)NULL + (12)) );
glVertexAttribPointerARB( 2, 2, GL_FLOAT, GL_FALSE, sizeof(Ovgl::Vertex), ((char *)NULL + (24)) );
glVertexAttribPointerARB( 3, 4, GL_FLOAT, GL_FALSE, sizeof(Ovgl::Vertex), ((char *)NULL + (32)) );
glVertexAttribPointerARB( 4, 4, GL_FLOAT, GL_FALSE, sizeof(Ovgl::Vertex), ((char *)NULL + (48)) );



I don't know what the index attribute is actually for but I'm pretty sure it has to do with the type of vertex data indicated by the tags. So this makes me wonder if there are tags and indices made specifically for bone weights and indices?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!