Skip to content

Commit d50a95e

Browse files
committed
Added GPU skinning vertex shader to default pak
1 parent 8be60d9 commit d50a95e

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
719 Bytes
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#define MAX_JOINT_COUNT 64
2+
3+
uniform mat4 skeletonMatrix[MAX_JOINT_COUNT];
4+
5+
attribute vec4 vBoneIndices;
6+
attribute vec4 vBoneWeights;
7+
8+
varying vec3 normal;
9+
varying vec4 pos;
10+
varying vec4 rawpos;
11+
varying vec4 vertexColor;
12+
13+
14+
mat3 m3( mat4 m )
15+
{
16+
mat3 result;
17+
18+
result[0][0] = m[0][0];
19+
result[0][1] = m[0][1];
20+
result[0][2] = m[0][2];
21+
22+
23+
result[1][0] = m[1][0];
24+
result[1][1] = m[1][1];
25+
result[1][2] = m[1][2];
26+
27+
result[2][0] = m[2][0];
28+
result[2][1] = m[2][1];
29+
result[2][2] = m[2][2];
30+
31+
return result;
32+
}
33+
34+
35+
void jointInfluence(in mat4 joint_matrix, in float weight, in vec4 position, inout vec4 outPosition, in vec3 normal, inout vec3 outNormal)
36+
{
37+
outPosition += weight * (joint_matrix * position);
38+
39+
mat3 normalMatrix = m3(joint_matrix);
40+
outNormal += weight * (normalMatrix * normal);
41+
}
42+
43+
void main() {
44+
45+
vec4 inVert = gl_Vertex;
46+
vec4 outVert = vec4(0.0, 0.0, 0.0, 0.0);
47+
48+
vec3 inNormal = gl_Normal;
49+
vec3 outNormal = vec3(0.0, 0.0, 0.0);
50+
51+
jointInfluence(skeletonMatrix[int(vBoneIndices.x)], vBoneWeights.x, inVert, outVert, inNormal, outNormal);
52+
jointInfluence(skeletonMatrix[int(vBoneIndices.y)], vBoneWeights.y, inVert, outVert, inNormal, outNormal);
53+
jointInfluence(skeletonMatrix[int(vBoneIndices.z)], vBoneWeights.z, inVert, outVert, inNormal, outNormal);
54+
jointInfluence(skeletonMatrix[int(vBoneIndices.w)], vBoneWeights.w, inVert, outVert, inNormal, outNormal);
55+
56+
57+
normal = gl_NormalMatrix * outNormal;
58+
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * outVert;
59+
pos = gl_ModelViewMatrix * outVert;
60+
rawpos = outVert;
61+
vertexColor = gl_Color;
62+
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
63+
}

0 commit comments

Comments
 (0)