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
|
@ -2,10 +2,13 @@ attribute vec3 attr_Position;
|
|||
attribute vec3 attr_Normal;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec3 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
//#endif
|
||||
#elif defined(USE_BONE_ANIMATION)
|
||||
attribute vec4 attr_BoneIndexes;
|
||||
attribute vec4 attr_BoneWeights;
|
||||
#endif
|
||||
|
||||
//#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
|
@ -17,9 +20,11 @@ uniform mat4 u_ModelViewProjectionMatrix;
|
|||
|
||||
uniform mat4 u_ModelMatrix;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
//#endif
|
||||
#elif defined(USE_BONE_ANIMATION)
|
||||
uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
|
||||
#endif
|
||||
|
||||
varying vec3 var_Position;
|
||||
|
||||
|
@ -78,8 +83,22 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
|||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
|
||||
#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);
|
||||
#else
|
||||
vec3 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#endif
|
||||
|
||||
position = DeformPosition(position, normal, attr_TexCoord0.st);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue