OpenGL2: Add GPU vertex skinning for IQM models
Using GPU vertex skinning is significantly faster than CPU vertex skinning. Especially since OpenGL2 has to run R_VaoPackNormal() and R_VaoPackTangent() each vertex each frame which causes CPU vertex skinning to be significantly slower than OpenGL1 renderer.
This commit is contained in:
parent
cccd283be8
commit
11337c9fa2
10 changed files with 533 additions and 34 deletions
|
@ -12,6 +12,9 @@ attribute vec4 attr_Tangent;
|
|||
attribute vec3 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
attribute vec4 attr_Tangent2;
|
||||
#elif defined(USE_BONE_ANIMATION)
|
||||
attribute vec4 attr_BoneIndexes;
|
||||
attribute vec4 attr_BoneWeights;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR)
|
||||
|
@ -48,6 +51,8 @@ uniform mat4 u_ModelMatrix;
|
|||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
#elif defined(USE_BONE_ANIMATION)
|
||||
uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
|
@ -151,6 +156,18 @@ void main()
|
|||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 tangent = mix(attr_Tangent.xyz, attr_Tangent2.xyz, u_VertexLerp);
|
||||
#endif
|
||||
#elif defined(USE_BONE_ANIMATION)
|
||||
mat4 vtxMat = u_BoneMatrix[int(attr_BoneIndexes.x)] * attr_BoneWeights.x;
|
||||
vtxMat += u_BoneMatrix[int(attr_BoneIndexes.y)] * attr_BoneWeights.y;
|
||||
vtxMat += u_BoneMatrix[int(attr_BoneIndexes.z)] * attr_BoneWeights.z;
|
||||
vtxMat += u_BoneMatrix[int(attr_BoneIndexes.w)] * attr_BoneWeights.w;
|
||||
mat3 nrmMat = mat3(cross(vtxMat[1].xyz, vtxMat[2].xyz), cross(vtxMat[2].xyz, vtxMat[0].xyz), cross(vtxMat[0].xyz, vtxMat[1].xyz));
|
||||
|
||||
vec3 position = vec3(vtxMat * vec4(attr_Position, 1.0));
|
||||
vec3 normal = normalize(nrmMat * attr_Normal);
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 tangent = normalize(nrmMat * attr_Tangent.xyz);
|
||||
#endif
|
||||
#else
|
||||
vec3 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue