| 1 |
// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#version 150 |
| 5 |
|
| 6 |
in vec3 vertexPosition; |
| 7 |
in vec3 vertexNormal; |
| 8 |
in vec4 vertexTangent; |
| 9 |
in vec2 vertexTexCoord; |
| 10 |
in ivec4 vertexJointIndices; |
| 11 |
in vec4 vertexJointWeights; |
| 12 |
|
| 13 |
out vec3 worldPosition; |
| 14 |
out vec3 worldNormal; |
| 15 |
out vec4 worldTangent; |
| 16 |
out vec2 texCoord; |
| 17 |
|
| 18 |
uniform mat4 modelMatrix; |
| 19 |
uniform mat3 modelNormalMatrix; |
| 20 |
uniform mat4 mvp; |
| 21 |
|
| 22 |
const int maxJoints = 100; |
| 23 |
uniform mat4 skinningPalette[maxJoints]; |
| 24 |
|
| 25 |
void main() |
| 26 |
{ |
| 27 |
// Pass the texture coordinates through |
| 28 |
texCoord = vertexTexCoord; |
| 29 |
|
| 30 |
// Perform the skinning |
| 31 |
mat4 skinningMatrix = skinningPalette[vertexJointIndices[0]] * vertexJointWeights[0]; |
| 32 |
skinningMatrix += skinningPalette[vertexJointIndices[1]] * vertexJointWeights[1]; |
| 33 |
skinningMatrix += skinningPalette[vertexJointIndices[2]] * vertexJointWeights[2]; |
| 34 |
skinningMatrix += skinningPalette[vertexJointIndices[3]] * vertexJointWeights[3]; |
| 35 |
|
| 36 |
vec4 skinnedPosition = skinningMatrix * vec4(vertexPosition, 1.0); |
| 37 |
vec3 skinnedNormal = vec3(skinningMatrix * vec4(vertexNormal, 0.0)); |
| 38 |
vec3 skinnedTangent = vec3(skinningMatrix * vec4(vertexTangent.xyz, 0.0)); |
| 39 |
|
| 40 |
// Transform position, normal, and tangent to world space |
| 41 |
worldPosition = vec3(modelMatrix * skinnedPosition); |
| 42 |
worldNormal = normalize(modelNormalMatrix * skinnedNormal); |
| 43 |
worldTangent.xyz = normalize(vec3(modelMatrix * vec4(skinnedTangent, 0.0))); |
| 44 |
worldTangent.w = vertexTangent.w; |
| 45 |
|
| 46 |
gl_Position = mvp * skinnedPosition; |
| 47 |
} |