Georgy
11-03-2006, 10:22 PM
I've created my first GLSL shader related to skeletal animation.
http://www.igrodel.ru/files/skeletal12.zip (exe+source in Turbo Delphi)
Some files required to this sample compile in Turbo Delphi: http://www.igrodel.ru/files/igrodel10.zip
vertex:
uniform mat4 boneMat[32];
varying float texNum;
void main(void)
{
float boneIndex[3];
float boneWeight[3];
texNum = gl_Vertex[3];
vec4 fixedTexCoord = gl_MultiTexCoord0;
vec4 fixedColor = gl_Color;
vec4 fixedVertex = gl_Vertex;
vec4 finalVertex = vec4(0,0,0,1);
boneIndex[0] = floor(fixedTexCoord[2]*255.0+0.001);
boneWeight[0] = fixedTexCoord[3];
boneIndex[1] = floor(fixedColor[0]*255.0+0.001);
boneWeight[1] = fixedColor[1];
boneIndex[2] = floor(fixedColor[2]*255.0+0.001);
boneWeight[2] = fixedColor[3];
fixedTexCoord[2] = 0.0;
fixedTexCoord[3] = 1.0;
fixedColor[0] = 1.0;
fixedColor[1] = 1.0;
fixedColor[2] = 1.0;
fixedColor[3] = 1.0;
fixedVertex[3] = 1.0;
mat4 finalMatrix = mat4(0);
for (int i = 0; i < 3; i++)
finalMatrix += boneWeight[i]*boneMat[int(boneIndex[i])];
finalVertex = finalMatrix*fixedVertex;
finalVertex[3] = 1.0;
gl_Position = gl_ModelViewProjectionMatrix * finalVertex;
gl_FrontColor = fixedColor;
gl_TexCoord[0] = fixedTexCoord;
} fragment:
uniform sampler2D myTexture0;
uniform sampler2D myTexture1;
uniform sampler2D myTexture2;
uniform sampler2D myTexture3;
uniform sampler2D myTexture4;
uniform sampler2D myTexture5;
uniform sampler2D myTexture6;
uniform sampler2D myTexture7;
varying float texNum;
void main(void)
{
float texNum2 = floor(texNum*255.0-1.0+0.001);
if (texNum2==0.0)
gl_FragColor = texture2D( myTexture0, gl_TexCoord[0].st );
else if (texNum2==1.0)
gl_FragColor = texture2D( myTexture1, gl_TexCoord[0].st );
else if (texNum2==2.0)
gl_FragColor = texture2D( myTexture2, gl_TexCoord[0].st );
else if (texNum2==3.0)
gl_FragColor = texture2D( myTexture3, gl_TexCoord[0].st );
else if (texNum2==4.0)
gl_FragColor = texture2D( myTexture4, gl_TexCoord[0].st );
else if (texNum2==5.0)
gl_FragColor = texture2D( myTexture5, gl_TexCoord[0].st );
else if (texNum2==6.0)
gl_FragColor = texture2D( myTexture6, gl_TexCoord[0].st );
else if (texNum2==7.0)
gl_FragColor = texture2D( myTexture7, gl_TexCoord[0].st );
}I need suggestions about how to make it work with ATI cards. Some peoples give me feedback that it does not work.
Also I am interested in what are you thinking about performance of my shader relative to what you've seen before.
And the last MYSTERIOUS THING:
when i using ".../255..." in my program and do the "...*255.0+0.001..." in shader perfomance is higher than without this bone/texture index "normalisation". Why?
http://www.igrodel.ru/files/skeletal12.zip (exe+source in Turbo Delphi)
Some files required to this sample compile in Turbo Delphi: http://www.igrodel.ru/files/igrodel10.zip
vertex:
uniform mat4 boneMat[32];
varying float texNum;
void main(void)
{
float boneIndex[3];
float boneWeight[3];
texNum = gl_Vertex[3];
vec4 fixedTexCoord = gl_MultiTexCoord0;
vec4 fixedColor = gl_Color;
vec4 fixedVertex = gl_Vertex;
vec4 finalVertex = vec4(0,0,0,1);
boneIndex[0] = floor(fixedTexCoord[2]*255.0+0.001);
boneWeight[0] = fixedTexCoord[3];
boneIndex[1] = floor(fixedColor[0]*255.0+0.001);
boneWeight[1] = fixedColor[1];
boneIndex[2] = floor(fixedColor[2]*255.0+0.001);
boneWeight[2] = fixedColor[3];
fixedTexCoord[2] = 0.0;
fixedTexCoord[3] = 1.0;
fixedColor[0] = 1.0;
fixedColor[1] = 1.0;
fixedColor[2] = 1.0;
fixedColor[3] = 1.0;
fixedVertex[3] = 1.0;
mat4 finalMatrix = mat4(0);
for (int i = 0; i < 3; i++)
finalMatrix += boneWeight[i]*boneMat[int(boneIndex[i])];
finalVertex = finalMatrix*fixedVertex;
finalVertex[3] = 1.0;
gl_Position = gl_ModelViewProjectionMatrix * finalVertex;
gl_FrontColor = fixedColor;
gl_TexCoord[0] = fixedTexCoord;
} fragment:
uniform sampler2D myTexture0;
uniform sampler2D myTexture1;
uniform sampler2D myTexture2;
uniform sampler2D myTexture3;
uniform sampler2D myTexture4;
uniform sampler2D myTexture5;
uniform sampler2D myTexture6;
uniform sampler2D myTexture7;
varying float texNum;
void main(void)
{
float texNum2 = floor(texNum*255.0-1.0+0.001);
if (texNum2==0.0)
gl_FragColor = texture2D( myTexture0, gl_TexCoord[0].st );
else if (texNum2==1.0)
gl_FragColor = texture2D( myTexture1, gl_TexCoord[0].st );
else if (texNum2==2.0)
gl_FragColor = texture2D( myTexture2, gl_TexCoord[0].st );
else if (texNum2==3.0)
gl_FragColor = texture2D( myTexture3, gl_TexCoord[0].st );
else if (texNum2==4.0)
gl_FragColor = texture2D( myTexture4, gl_TexCoord[0].st );
else if (texNum2==5.0)
gl_FragColor = texture2D( myTexture5, gl_TexCoord[0].st );
else if (texNum2==6.0)
gl_FragColor = texture2D( myTexture6, gl_TexCoord[0].st );
else if (texNum2==7.0)
gl_FragColor = texture2D( myTexture7, gl_TexCoord[0].st );
}I need suggestions about how to make it work with ATI cards. Some peoples give me feedback that it does not work.
Also I am interested in what are you thinking about performance of my shader relative to what you've seen before.
And the last MYSTERIOUS THING:
when i using ".../255..." in my program and do the "...*255.0+0.001..." in shader perfomance is higher than without this bone/texture index "normalisation". Why?