PDA

View Full Version : GLSL problems on some cards



Phantasy
04-03-2007, 09:44 AM
Hi !

I'm working on a project that requires many skinned characters in a scene and to increase the performance I'm using shaders for the skinning, but I've received some reports about problems on those graphics cards: ATI X600 Mobility Radeon, ATI X1300 Mobility Radeon and Nvidia QuadroFX Go 700.

I've written a GLSL shader which is based on the vertex skinning example from the book Cg Tutorial. On the computers both the GLSL and the original Cg shader was tested.

The problems appears to be pretty random, but the reports are:

On the ATI X600 (Sony Vaio, driver version 6.14.10.6483, which I've been able to do some tests on) there is some strange problem with the arrays, causing the last elements to be corrupt which makes the result to look as it should until it uses the last values of the array. I suspect it's a hardware error, but it might be the drivers since they're from 2004. Cg doesn't work either.

On the ATI X1300 (Acer, driver version 8.205.0.0) it was reported that the characters were "2D". I haven't seen it myself but as I understood it they appears flat when they're rotating. The Cg version of the shader works with no problems.

On the Nvidia QuadroFX (Dell, driver version ForceWare 78.11) the characters didn't animate. I haven't been able to do some tests with this computer, but the Cg version was reported to work.

So my question is, has anyone had similar problems with those graphics cards or if there might be a solution to the problems ?

The GLSL shader:

attribute vec4 matrixIndex;
attribute vec4 weight;

uniform mat4 transform;
uniform vec4 skinMatrix[57];

varying vec4 normal;

void main()
{
vec4 p = vec4(0, 0, 0, 0);
vec3 n = vec3(0, 0, 0);

for (int i = 0; i < 4; ++i)
{
int index = int(matrixIndex[i]);
mat4 matrix = mat4( skinMatrix[index*3+0],
skinMatrix[index*3+1],
skinMatrix[index*3+2],
vec4(0, 0, 0, 1));
matrix = mat4( matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0],
matrix[0][1], matrix[1][1], matrix[2][1], matrix[3][1],
matrix[0][2], matrix[1][2], matrix[2][2], matrix[3][2],
matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]);
vec4 skinPosition = matrix*gl_Vertex;
mat3 rotate = mat3( matrix[0].xyz,
matrix[1].xyz,
matrix[2].xyz);
vec3 skinNormal = rotate*gl_Normal;
p += weight[i] * skinPosition;
n += weight[i] * skinNormal;
}

gl_Position = gl_ModelViewProjectionMatrix*p;

normal = vec4(n, 1);

gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord1;

gl_FrontColor = gl_Color;
}
The Cg shader:

void main( float3 position : POSITION,
float3 normal : NORMAL,
float2 texCoord0 : TEXCOORD0,
float2 texCoord1 : TEXCOORD1,
float4 weight : TEXCOORD2,
float4 matrixIndex : TEXCOORD3,

out float4 oPosition : POSITION,
out float2 oTexCoord0 : TEXCOORD0,
out float2 oTexCoord1 : TEXCOORD1,
out float3 oNormal : TEXCOORD2,
out float4 oColor : COLOR,

uniform float4x4 transform,
uniform float4 skinMatrix[57],
uniform float4x4 mvp : state.matrix.mvp)
{
float3 p = float3(0, 0, 0);
float3 n = float3(0, 0, 0);

int index;
float3x4 matrix;
float3 skinPosition, skinNormal;

for (int i = 0; i < 4; ++i)
{
index = matrixIndex[i];
matrix = float3x4( skinMatrix[index*3+0],
skinMatrix[index*3+1],
skinMatrix[index*3+2]);
skinPosition = mul(matrix, float4(position, 1));
skinNormal = mul(float3x3(matrix), normal);
p += weight[i] * skinPosition;
n += weight[i] * skinNormal;
}

oNormal = mul(float3x3(transform), normalize(normal));

oPosition = mul(mvp, float4(p, 1));

oColor = normalize(float4(position, 1));

oTexCoord0 = texCoord0;
oTexCoord1 = texCoord1;
}Thanks in advance !

Martin