Cg Shader problem

Started by
3 comments, last by MrDoomMaster 15 years, 11 months ago
Hi, I'm compiling my Cg Shader for the profile arbvp1, however for some reason it won't let me use BLENDWEIGHT. I'll show you the source code below:
struct vertex_in
{
	float3 position		: POSITION;
	float3 normal		: NORMAL;
	float3 tangent		: TANGENT;
	float4 weights		: BLENDWEIGHT;
	int4 indices		: BLENDINDICES;
	float2 uv			: TEXCOORD0;
};

struct vertex_out
{
	float4 position		: POSITION;
	float2 texCoord		: TEXCOORD0;
	float3 normal		: TEXCOORD1;
};


// the main function
vertex_out main(	vertex_in IN,
					uniform float4x4 bones[5],
					uniform float4x4 modelView : state.matrix.modelview[0],
					uniform float4x4 projection : state.matrix.projection
					)

{
	vertex_out OUT;
	
	// skin the vertex position and normal
	float4 position = float4(IN.position, 1);
	float4 normal	= float4(IN.normal, 0);

	// the skinned attributes
	float3 skinnedPos    = (float3)0;
	float3 skinnedNormal = (float3)0;
	
	// perform the skinning
	for(unsigned int i=0; i<4; ++i)
	{
		skinnedPos    += (mul( position, bones[IN.indices] ) * IN.weights).xyz;
		skinnedNormal += (mul( normal, bones[IN.indices] ) * IN.weights).xyz;
	}

	skinnedPos		= mul( modelView, float4(skinnedPos,1) ).xyz;
	OUT.position	= mul( projection, float4(skinnedPos,1) );
	OUT.normal		= mul( modelView, float4(skinnedNormal, 1) ).xyz;
	OUT.texCoord	= IN.uv;

	return OUT;
}

This is the error I'm getting when I run it through the compiler: warning C7019: "weights" is too large for semantic "BLENDWEIGHT", which is size 1 And this is the command line I'm using: cgc test.cg -profile arbvp1 -nocode Does anyone know why it isn't working? I'm new to shaders, so go easy on me.
Advertisement
try float weights : BLENDWEIGHT; instead of float4, since BLENDWEIGHT is size 1.
im just guessing, i dont know cg
yet, another stupid signature..
I'm sending 4 float values in BLENDWEIGHT, so I need it to be float4. In the Cg documentation, they have Cg samples (under Improved skinning examples) that define BLENDWEIGHT as a float4.
Why don't you use a texcoord for your weights? Use TEXCOORD1

And what about this? I think GPUs prefer working with float
int4 indices : BLENDINDICES;

Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by V-man
Why don't you use a texcoord for your weights? Use TEXCOORD1

And what about this? I think GPUs prefer working with float
int4 indices : BLENDINDICES;


This might be a good work around for now, but I still need to figure out why my shader isn't working with BLENDWEIGHT.

Also, the BLENDINDICES binding used to be a float4, however I switched it to int4 to see if it would work. They're indices, so it would make sense for them to be integers, not floats. If it doesn't work I was going to switch it back to float4

This topic is closed to new replies.

Advertisement