• Advertisement
Sign in to follow this  

GLSL skeletal animation and varying values problem

This topic is 3036 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 make a simple skeletal animation shader, with normal mapping. Currently the skeletal animation works fine, and the lighting works fine, but the problem seems to occur when I try to use them together. If I comment out the 4 lines that deal with combining the weighted bone matrices, all the lighting and texturing works fine. If I leave them in however, it seems to screw with one of my varying values, setting it to 0, currently it's messing with vTexCoord, but before I had that in there, it changed the values in vLightDir, is this some sort of driver bug or am I doing something I shouldn't? Also when I try to use mat4x3, I get an error ("mat4x3: syntanx error syntax error"), even though glGetString(GL_SHADING_LANGUAGE_VERSION) claims to be version 1.20. Currently working on a mac with gfx card: ATI Radeon HD 2600. Any help greatly appreciated, thanks! Vertex shader
/* Uniforms */
uniform mat4 boneMats[64];
uniform vec3 lightDir;

/* Attributes */
attribute vec4 bones;
attribute vec4 weights;

attribute vec3 tangent, bitangent;

/* Varying */
varying vec3 vLightDir;
varying vec3 vEyeVec;
varying vec2 vTexCoord;

void main()
{
	/*	Tex Coord	*/
	vTexCoord = gl_MultiTexCoord0.st;

	/*	Vertex Position		*/
	vec3 pos = vec3(0.0,0.0,0.0);
	vec3 normal = vec3(0.0,0.0,0.0);
	ivec4 iBones = ivec4(bones[0], bones[1], bones[2], bones[3]);

	// These next 4 lines seem to cause the problem
	pos += weights[0] * (boneMats[iBones[0]] * gl_Vertex).xyz;
	pos += weights[1] * (boneMats[iBones[1]] * gl_Vertex).xyz;
	pos += weights[2] * (boneMats[iBones[2]] * gl_Vertex).xyz;
	pos += weights[3] * (boneMats[iBones[3]] * gl_Vertex).xyz;

	gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
	//gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

	/*	Lighting		*/
	vec3 n = normalize(gl_NormalMatrix * gl_Normal);		// normal
	vec3 t = normalize(gl_NormalMatrix * tangent);			// tangent
	vec3 b = normalize(gl_NormalMatrix * bitangent);		// bitangent
	vec3 l = normalize(gl_NormalMatrix * -lightDir);		// vecToLight
	vec3 e = vec3(gl_ModelViewMatrix * gl_Vertex);			// vecToEye

	vLightDir = vec3(
		dot(l, t),
		dot(l, b),
		dot(l, n)
	);

	vEyeVec = vec3(
		dot(e, t),
		dot(e, b),
		dot(e, n)
	);
}

Fragment shader
/* Uniforms */
uniform sampler2D diffuse, specular, normal;
uniform float shininess;

/* Varying */
varying vec3 vLightDir;
varying vec3 vEyeVec;
varying vec2 vTexCoord;

void main() {
	/*	Read from textures	*/
	vec4 matDiffuse = texture2D(diffuse, vTexCoord);
	vec4 matSpecular = texture2D(specular, vTexCoord);
	vec3 matNormal = vec3(texture2D(normal, vTexCoord));

	/*	Ambient component	*/
	vec4 fAmbient = vec4(0.2, 0.2, 0.2, 1.0) * matDiffuse;

	/*	Diffuse component	*/
	matNormal = normalize((matNormal - 0.5) * 2.0);
	float diffAmt = max( dot(matNormal, vLightDir), 0.0 );

	vec4 fDiffuse = vec4(0.4, 0.4, 0.4, 1.0) * matDiffuse * diffAmt;

	/*	Specular component	*/
	float specAmt = pow( clamp( dot(reflect( vLightDir, matNormal), normalize(vEyeVec)), 0.0, 1.0), shininess);
	vec4 fSpecular = vec4(1.0, 1.0, 1.0, 1.0) * matSpecular * specAmt;

	gl_FragColor = fAmbient + fDiffuse + fSpecular;
	gl_FragColor.a = 1.0;
}

Share this post


Link to post
Share on other sites
Advertisement
Nothing jumps out at me that's wrong in your shaders.

There's a software renderer that Apple ships with OpenGL. If your program works with that, it *might* be a driver bug. See http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_pixelformats/opengl_pixelformats.html

But these are fairly simple shaders, my gut instinct would be a problem with your application itself. Have you tried querying uniform limits to see if you're going over? 64 4x4 matrices is 1024 floats, which could totally be going over (I'm not familiar with the Radeon 2600). Try dropping it to 32 for testing.

Share this post


Link to post
Share on other sites
GL_MAX_VERTEX_UNIFORM_COMPONENTS = 4096, so I don't think there's a problem there. I tried to run with the software renderer, and it still did not appear to work, so I guess that would mean a problem with my code, though at this point I have no Idea where to even begin...

Share this post


Link to post
Share on other sites
Well I just install osx 10.6, and it seems to be working correctly now, thanks your for your help though.

Share this post


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

  • Advertisement