Sign in to follow this  
rgibson11

Shader translation code

Recommended Posts

rgibson11    130
Can someone who understands the 'ARB' shading language please help me.
I had this problem over 6 months now. I am trying to translate the cal3d shader code to glsl and it works fine when model is standing still but when I move the characters hands go to places they should go, making it look like a monster.

I know not many people understand 'ARB' but I thought I may as well try post here.


char vertexProgramStr[]=
"!!ARBvp1.0\n""PARAM constant = { 1, 3, 0, 0 };
\n""TEMP R0, R1, R2, R3, R4, R5;
\n""ADDRESS A0;
\n""ATTRIB texCoord = vertex.attrib[8];
\n""ATTRIB normal = vertex.attrib[2];
\n""ATTRIB index = vertex.attrib[3];
\n""ATTRIB weight = vertex.attrib[1];
\n""ATTRIB position = vertex.attrib[0];
\n""PARAM worldViewProjMatrix[4] = { state.matrix.mvp };
\n""PARAM diffuse = state.material.diffuse;
\n""PARAM ambient = state.material.ambient;
\n""PARAM lightDir = state.light[0].position;
\n""PARAM matrix[87] = { program.local[0..86] };
\n""\n""MOV result.texcoord[0].xy, texCoord.xyxx;
\n""\n""MUL R4, index, constant.y;
\n""\n""ARL A0.x, R4.y;
\n""DP3 R0.x, matrix[A0.x].xyzx, normal.xyzx;
\n""DP3 R0.y, matrix[A0.x + 1].xyzx, normal.xyzx;
\n""DP3 R0.z, matrix[A0.x + 2].xyzx, normal.xyzx;
\n""MUL R1.yzw, R0.xxyz, weight.y;
\n""\n""ARL A0.x, R4.x;
\n""DP3 R0.x, matrix[A0.x].xyzx, normal.xyzx;
\n""DP3 R0.y, matrix[A0.x + 1].xyzx, normal.xyzx;
\n""DP3 R0.z, matrix[A0.x + 2].xyzx, normal.xyzx;
\n""MAD R1.yzw, R0.xxyz, weight.x, R1.yyzw;
\n""\n""DP3 R0.x, R1.yzwy, R1.yzwy;
\n""RSQ R0.x, R0.x;
\n""MUL R0.xyz, R0.x, R1.yzwy;\n""DP3 R1.x, lightDir.xyzx, lightDir.xyzx;
\n""RSQ R1.x, R1.x;
\n""MUL R2.xyz, R1.x, lightDir.xyzx;
\n""DP3 R0.x, R0.xyzx, R2.xyzx;
\n""MAX R0.x, R0.x, constant.z;
\n""ADD R0, R0.x, ambient;
\n""MUL result.color.front.primary, R0, diffuse;
\n""\n""ARL A0.x, R4.w;
\n""DPH R0.x, position.xyzx, matrix[A0.x];
\n""DPH R0.y, position.xyzx, matrix[A0.x + 1];
\n""DPH R0.z, position.xyzx, matrix[A0.x + 2];
\n""\n""ARL A0.x, R4.z;
\n""DPH R3.x, position.xyzx, matrix[A0.x];
\n""DPH R3.y, position.xyzx, matrix[A0.x + 1];
\n""DPH R3.z, position.xyzx, matrix[A0.x + 2];
\n""\n""ARL A0.x, R4.y;
\n""DPH R1.y, position.xyzx, matrix[A0.x];
\n""DPH R1.z, position.xyzx, matrix[A0.x + 1];
\n""DPH R1.w, position.xyzx, matrix[A0.x + 2];
\n""MUL R2.xyz, R1.yzwy, weight.y;
\n""\n""ARL A0.x, R4.x;
\n""DPH R1.x, position.xyzx, matrix[A0.x];
\n""DPH R1.y, position.xyzx, matrix[A0.x + 1];
\n""DPH R1.z, position.xyzx, matrix[A0.x + 2];
\n""\n""MAD R1.xyz, R1.xyzx, weight.x, R2.xyzx;
\n""MAD R1.xyz, R3.xyzx, weight.z, R1.xyzx;
\n""MAD R0.xyz, R0.xyzx, weight.w, R1.xyzx;
\n""\n""DPH result.position.x, R0.xyzx, worldViewProjMatrix[0];
\n""DPH result.position.y, R0.xyzx, worldViewProjMatrix[1];
\n""DPH result.position.z, R0.xyzx, worldViewProjMatrix[2];
\n""DPH result.position.w, R0.xyzx, worldViewProjMatrix[3];
\n""END\n";





uniform mat4 World;
uniform mat4 View;
uniform mat4 Proj;

attribute vec4 weight;
attribute vec4 index;

const int max_bones = 29;
uniform vec4 BoneMatrix[max_bones*3];

vec4 getVertex(){

vec4 R0, R1, R2, R3;
int actIndex;
vec3 pos = gl_Vertex.xyz;
//v
actIndex = int(index.w) * 3;
R0.x = dot(pos.xyz, BoneMatrix[actIndex].xyz) + BoneMatrix[actIndex].w; //DPH R0.x, position.xyzz, matrix[A0.x];
R0.y = dot(pos.xyz, BoneMatrix[actIndex+1].xyz) + BoneMatrix[actIndex+1].w; //DPH R0.y, position.xyzz, matrix[A0.x + 1];
R0.z = dot(pos.xyz, BoneMatrix[actIndex+2].xyz) + BoneMatrix[actIndex+2].w; //DPH R0.z, position.xyzz, matrix[A0.x + 2];

actIndex = int(index.x) * 3;
R1.x = dot(pos.xyz, BoneMatrix[actIndex].xyz) + BoneMatrix[actIndex].w; //DPH R1.y, position.xyzx, matrix[A0.x];
R1.y = dot(pos.xyz, BoneMatrix[actIndex+1].xyz) + BoneMatrix[actIndex+1].w; //DPH R1.z, position.xyzx, matrix[A0.x + 1];
R1.z = dot(pos.xyz, BoneMatrix[actIndex+2].xyz) + BoneMatrix[actIndex+2].w; //DPH R1.w, position.xyzx, matrix[A0.x + 2];
actIndex = int(index.y) * 3;
R2.x = dot(pos.xyz, BoneMatrix[actIndex].xyz) + BoneMatrix[actIndex].w; //DPH R2.x, position.xyzx, matrix[A0.x];
R2.y = dot(pos.xyz, BoneMatrix[actIndex+1].xyz) + BoneMatrix[actIndex+1].w; //DPH R2.y, position.xyzx, matrix[A0.x + 1];
R2.z = dot(pos.xyz, BoneMatrix[actIndex+2].xyz) + BoneMatrix[actIndex+2].w; //DPH R2.z, position.xyzx, matrix[A0.x + 2];
actIndex = int(index.z) * 3;
R3.x = dot(pos.xyz, BoneMatrix[actIndex].xyz) + BoneMatrix[actIndex].w; //DPH R3.x, position.xyzx, matrix[A0.x];
R3.y = dot(pos.xyz, BoneMatrix[actIndex+1].xyz) + BoneMatrix[actIndex+1].w; //DPH R3.y, position.xyzx, matrix[A0.x + 1];
R3.z = dot(pos.xyz, BoneMatrix[actIndex+2].xyz) + BoneMatrix[actIndex+2].w; //DPH R3.z, position.xyzx, matrix[A0.x + 2];
R0 *= weight.w;
R1 *= weight.x;
R2 *= weight.y;
R3 *= weight.z;

R0 = R0 + R1 + R2 + R3;
R0.w = 1.0;

return R0;
}

vec3 getNormal(void){
vec4 N0, N1, N2;
vec3 normal;
normal = gl_Normal;
int actIndex;

actIndex = int(index.x) * 3;
N1.x = dot(normal.xyzx, BoneMatrix[actIndex].xyzx); //DPH R1.y, position.xyzx, matrix[A0.x];
N1.y = dot(normal.xyzx, BoneMatrix[actIndex+1].xyzx); //DPH R1.z, position.xyzx, matrix[A0.x + 1];
N1.z = dot(normal.xyzx, BoneMatrix[actIndex+2].xyzx); //DPH R1.w, position.xyzx, matrix[A0.x + 2];
actIndex = int(index.y) * 3;
N2.x = dot(normal.xyzx, BoneMatrix[actIndex].xyzx); //DPH R2.x, position.xyzx, matrix[A0.x];
N2.y = dot(normal.xyzx, BoneMatrix[actIndex+1].xyzx); //DPH R2.y, position.xyzx, matrix[A0.x + 1];
N2.z = dot(normal.xyzx, BoneMatrix[actIndex+2].xyzx); //DPH R2.z, position.xyzx, matrix[A0.x + 2];

vec4 N3, N4;
actIndex = int(index.z) * 3;
N3.x = dot(normal.xyzx, BoneMatrix[actIndex].xyzx); //DPH R1.y, position.xyzx, matrix[A0.x];
N3.y = dot(normal.xyzx, BoneMatrix[actIndex+1].xyzx); //DPH R1.z, position.xyzx, matrix[A0.x + 1];
N3.z = dot(normal.xyzx, BoneMatrix[actIndex+2].xyzx); //DPH R1.w, position.xyzx, matrix[A0.x + 2];
actIndex = int(index.w) * 3;
N4.x = dot(normal.xyzx, BoneMatrix[actIndex].xyzx); //DPH R2.x, position.xyzx, matrix[A0.x];
N4.y = dot(normal.xyzx, BoneMatrix[actIndex+1].xyzx); //DPH R2.y, position.xyzx, matrix[A0.x + 1];
N4.z = dot(normal.xyzx, BoneMatrix[actIndex+2].xyzx);

N1 *= weight.x;
N2 *= weight.y;
N3 *= weight.z;
N4 *= weight.w; //?
N0 = N1 + N2 + N3 + N4;
//N0 sollte die richtige normale sein
return N0.xyz;
}

void main (void)
{
mat4 VP = (View * Proj);
mat4 WVP = (World * View * Proj);
mat4 WV = (World * View);

mat4 W = World;
mat4 V = View;
mat4 P = Proj;

vec4 avertex = getVertex();
gl_Position = avertex * WVP;
}



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this