Fix skin shader

TODO: test on vc4
This commit is contained in:
Shinovon 2026-05-03 06:33:11 +05:00
parent f484ef9460
commit 0ad6fe45d1
6 changed files with 21 additions and 86 deletions

View file

@ -340,11 +340,10 @@ skinClose(void *o, int32, int32)
void
initSkin(void)
{
// TODO
// u_boneMatrices = registerUniform("u_boneMatrices", UNIFORM_MAT4, MAX_BONES);
//
// Driver::registerPlugin(PLATFORM_GL3, 0, ID_SKIN,
// skinOpen, skinClose);
u_boneMatrices = registerUniform("u_boneMatrices", UNIFORM_MAT4, MAX_BONES);
Driver::registerPlugin(PLATFORM_GL3, 0, ID_SKIN,
skinOpen, skinClose);
}
ObjPipeline*

View file

@ -5,55 +5,23 @@ VSIN(ATTRIB_POS) vec3 in_pos;
VSOUT vec4 v_color;
VSOUT vec3 v_tex0_fog;
mat4 getBoneMatrix(int idx) {
if(idx == 0) return u_boneMatrices[0];
if(idx == 1) return u_boneMatrices[1];
if(idx == 2) return u_boneMatrices[2];
if(idx == 3) return u_boneMatrices[3];
if(idx == 4) return u_boneMatrices[4];
if(idx == 5) return u_boneMatrices[5];
if(idx == 6) return u_boneMatrices[6];
if(idx == 7) return u_boneMatrices[7];
if(idx == 8) return u_boneMatrices[8];
if(idx == 9) return u_boneMatrices[9];
if(idx == 10) return u_boneMatrices[10];
if(idx == 11) return u_boneMatrices[11];
if(idx == 12) return u_boneMatrices[12];
if(idx == 13) return u_boneMatrices[13];
if(idx == 14) return u_boneMatrices[14];
if(idx == 15) return u_boneMatrices[15];
if(idx == 16) return u_boneMatrices[16];
if(idx == 17) return u_boneMatrices[17];
if(idx == 18) return u_boneMatrices[18];
if(idx == 19) return u_boneMatrices[19];
if(idx == 20) return u_boneMatrices[20];
if(idx == 21) return u_boneMatrices[21];
if(idx == 22) return u_boneMatrices[22];
if(idx == 23) return u_boneMatrices[23];
return u_boneMatrices[0];
}
void
main(void)
{
vec3 SkinVertex = vec3(0.0, 0.0, 0.0);
vec3 SkinNormal = vec3(0.0, 0.0, 0.0);
for(int i = 0; i < 4; i++){
SkinVertex += (getBoneMatrix(int(in_indices[i])) * vec4(in_pos, 1.0)).xyz * in_weights[i];
SkinNormal += (mat3(getBoneMatrix(int(in_indices[i]))) * in_normal) * in_weights[i];
}
SkinVertex += (u_boneMatrices[int(in_indices.x)] * vec4(in_pos, 1.0)).xyz * in_weights.x;
SkinVertex += (u_boneMatrices[int(in_indices.y)] * vec4(in_pos, 1.0)).xyz * in_weights.y;
SkinVertex += (u_boneMatrices[int(in_indices.z)] * vec4(in_pos, 1.0)).xyz * in_weights.z;
SkinVertex += (u_boneMatrices[int(in_indices.w)] * vec4(in_pos, 1.0)).xyz * in_weights.w;
vec4 Vertex = u_world * vec4(SkinVertex, 1.0);
gl_Position = u_proj * u_view * Vertex;
vec3 Normal = mat3(u_world) * SkinNormal;
v_tex0_fog.xy = in_tex0;
v_color = in_color;
v_color.rgb += u_ambLight.rgb*surfAmbient;
v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;
v_color = clamp(v_color, 0.0, 1.0);
v_color *= u_matColor;
v_tex0_fog.z = DoFog(gl_Position.z);
v_tex0_fog = vec3(in_tex0.x, in_tex0.y, DoFog(gl_Position.w));
}

View file

@ -6,56 +6,24 @@ const char *skin_vert_src =
"VSOUT vec4 v_color;\n"
"VSOUT vec3 v_tex0_fog;\n"
"mat4 getBoneMatrix(int idx) {\n"
" if(idx == 0) return u_boneMatrices[0];\n"
" if(idx == 1) return u_boneMatrices[1];\n"
" if(idx == 2) return u_boneMatrices[2];\n"
" if(idx == 3) return u_boneMatrices[3];\n"
" if(idx == 4) return u_boneMatrices[4];\n"
" if(idx == 5) return u_boneMatrices[5];\n"
" if(idx == 6) return u_boneMatrices[6];\n"
" if(idx == 7) return u_boneMatrices[7];\n"
" if(idx == 8) return u_boneMatrices[8];\n"
" if(idx == 9) return u_boneMatrices[9];\n"
" if(idx == 10) return u_boneMatrices[10];\n"
" if(idx == 11) return u_boneMatrices[11];\n"
" if(idx == 12) return u_boneMatrices[12];\n"
" if(idx == 13) return u_boneMatrices[13];\n"
" if(idx == 14) return u_boneMatrices[14];\n"
" if(idx == 15) return u_boneMatrices[15];\n"
" if(idx == 16) return u_boneMatrices[16];\n"
" if(idx == 17) return u_boneMatrices[17];\n"
" if(idx == 18) return u_boneMatrices[18];\n"
" if(idx == 19) return u_boneMatrices[19];\n"
" if(idx == 20) return u_boneMatrices[20];\n"
" if(idx == 21) return u_boneMatrices[21];\n"
" if(idx == 22) return u_boneMatrices[22];\n"
" if(idx == 23) return u_boneMatrices[23];\n"
" return u_boneMatrices[0];\n"
"}\n"
"void\n"
"main(void)\n"
"{\n"
" vec3 SkinVertex = vec3(0.0, 0.0, 0.0);\n"
" vec3 SkinNormal = vec3(0.0, 0.0, 0.0);\n"
" for(int i = 0; i < 4; i++){\n"
" SkinVertex += (getBoneMatrix(int(in_indices[i])) * vec4(in_pos, 1.0)).xyz * in_weights[i];\n"
" SkinNormal += (mat3(getBoneMatrix(int(in_indices[i]))) * in_normal) * in_weights[i];\n"
" }\n"
" \n"
" SkinVertex += (u_boneMatrices[int(in_indices.x)] * vec4(in_pos, 1.0)).xyz * in_weights.x;\n"
" SkinVertex += (u_boneMatrices[int(in_indices.y)] * vec4(in_pos, 1.0)).xyz * in_weights.y;\n"
" SkinVertex += (u_boneMatrices[int(in_indices.z)] * vec4(in_pos, 1.0)).xyz * in_weights.z;\n"
" SkinVertex += (u_boneMatrices[int(in_indices.w)] * vec4(in_pos, 1.0)).xyz * in_weights.w;\n"
" vec4 Vertex = u_world * vec4(SkinVertex, 1.0);\n"
" gl_Position = u_proj * u_view * Vertex;\n"
" vec3 Normal = mat3(u_world) * SkinNormal;\n"
" v_tex0_fog.xy = in_tex0;\n"
" v_color = in_color;\n"
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n"
" v_color = clamp(v_color, 0.0, 1.0);\n"
" v_color *= u_matColor;\n"
" v_tex0_fog.z = DoFog(gl_Position.z);\n"
" v_tex0_fog = vec3(in_tex0.x, in_tex0.y, DoFog(gl_Position.w));\n"
"}\n"
;