2019-05-10 23:51:59 +02:00
|
|
|
|
#version 330
|
|
|
|
|
|
|
|
|
|
const int MY_ARRAY_SIZE = 200;
|
|
|
|
|
|
|
|
|
|
in vec3 vPosition;
|
|
|
|
|
in vec3 vNormal;
|
2019-05-11 22:11:27 +02:00
|
|
|
|
in vec3 vTangent;
|
|
|
|
|
in vec2 vUV0;
|
|
|
|
|
in vec4 vColor;
|
|
|
|
|
in vec4 vBone;
|
|
|
|
|
in vec4 vWeight;
|
|
|
|
|
in vec2 vUV1;
|
|
|
|
|
in vec2 vUV2;
|
|
|
|
|
|
|
|
|
|
out vec2 f_texcoord0;
|
|
|
|
|
out vec2 f_texcoord1;
|
|
|
|
|
out vec2 f_texcoord2;
|
|
|
|
|
out vec2 f_texcoord3;
|
2019-05-10 23:51:59 +02:00
|
|
|
|
|
|
|
|
|
out vec3 normal;
|
2019-05-11 22:11:27 +02:00
|
|
|
|
out vec4 color;
|
2019-05-10 23:51:59 +02:00
|
|
|
|
out vec3 position;
|
|
|
|
|
|
2019-05-12 02:51:23 +02:00
|
|
|
|
out vec3 boneWeightsColored;
|
|
|
|
|
|
2019-05-12 03:17:49 +02:00
|
|
|
|
uniform int boneIds[190];
|
|
|
|
|
|
2019-05-11 22:11:27 +02:00
|
|
|
|
// Skinning uniforms
|
|
|
|
|
uniform mat4 bones[190];
|
|
|
|
|
|
2019-05-10 23:51:59 +02:00
|
|
|
|
uniform mat4 mtxCam;
|
|
|
|
|
uniform mat4 mtxMdl;
|
|
|
|
|
uniform mat4 previewScale;
|
|
|
|
|
|
2019-05-12 02:51:23 +02:00
|
|
|
|
// Bone Weight Display
|
|
|
|
|
uniform sampler2D weightRamp1;
|
|
|
|
|
uniform sampler2D weightRamp2;
|
|
|
|
|
uniform int selectedBoneIndex;
|
|
|
|
|
uniform int debugOption;
|
|
|
|
|
|
|
|
|
|
uniform int NoSkinning;
|
|
|
|
|
uniform int RigidSkinning;
|
|
|
|
|
uniform int SingleBoneIndex;
|
|
|
|
|
|
2019-05-11 22:11:27 +02:00
|
|
|
|
vec4 skin(vec3 pos, ivec4 index)
|
|
|
|
|
{
|
|
|
|
|
vec4 newPosition = vec4(pos.xyz, 1.0);
|
|
|
|
|
|
|
|
|
|
newPosition = bones[index.x] * vec4(pos, 1.0) * vWeight.x;
|
|
|
|
|
newPosition += bones[index.y] * vec4(pos, 1.0) * vWeight.y;
|
|
|
|
|
newPosition += bones[index.z] * vec4(pos, 1.0) * vWeight.z;
|
|
|
|
|
if (vWeight.w < 1) //Necessary. Bones may scale weirdly without
|
|
|
|
|
newPosition += bones[index.w] * vec4(pos, 1.0) * vWeight.w;
|
|
|
|
|
|
|
|
|
|
return newPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec3 skinNRM(vec3 nr, ivec4 index)
|
|
|
|
|
{
|
|
|
|
|
vec3 newNormal = vec3(0);
|
|
|
|
|
|
|
|
|
|
newNormal = mat3(bones[index.x]) * nr * vWeight.x;
|
|
|
|
|
newNormal += mat3(bones[index.y]) * nr * vWeight.y;
|
|
|
|
|
newNormal += mat3(bones[index.z]) * nr * vWeight.z;
|
|
|
|
|
newNormal += mat3(bones[index.w]) * nr * vWeight.w;
|
|
|
|
|
|
|
|
|
|
return newNormal;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-12 02:51:23 +02:00
|
|
|
|
vec3 BoneWeightColor(float weights)
|
|
|
|
|
{
|
|
|
|
|
float rampInputLuminance = weights;
|
|
|
|
|
rampInputLuminance = clamp((rampInputLuminance), 0.001, 0.999);
|
|
|
|
|
if (debugOption == 1) // Greyscale
|
|
|
|
|
return vec3(weights);
|
|
|
|
|
else if (debugOption == 2) // Color 1
|
|
|
|
|
return texture(weightRamp1, vec2(1 - rampInputLuminance, 0.50)).rgb;
|
|
|
|
|
else // Color 2
|
|
|
|
|
return texture(weightRamp2, vec2(1 - rampInputLuminance, 0.50)).rgb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float BoneWeightDisplay(ivec4 index)
|
|
|
|
|
{
|
|
|
|
|
float weight = 0;
|
2019-05-12 03:17:49 +02:00
|
|
|
|
if (selectedBoneIndex == boneIds[index.x])
|
2019-05-12 02:51:23 +02:00
|
|
|
|
weight += vWeight.x;
|
2019-05-12 03:17:49 +02:00
|
|
|
|
if (selectedBoneIndex == boneIds[index.y])
|
2019-05-12 02:51:23 +02:00
|
|
|
|
weight += vWeight.y;
|
2019-05-12 03:17:49 +02:00
|
|
|
|
if (selectedBoneIndex == boneIds[index.z])
|
2019-05-12 02:51:23 +02:00
|
|
|
|
weight += vWeight.z;
|
2019-05-12 03:17:49 +02:00
|
|
|
|
if (selectedBoneIndex == boneIds[index.w])
|
2019-05-12 02:51:23 +02:00
|
|
|
|
weight += vWeight.w;
|
|
|
|
|
|
2019-05-12 03:17:49 +02:00
|
|
|
|
if (selectedBoneIndex == boneIds[index.x] && RigidSkinning == 1)
|
2019-05-12 02:51:23 +02:00
|
|
|
|
weight = 1;
|
|
|
|
|
if (selectedBoneIndex == SingleBoneIndex && NoSkinning == 1)
|
|
|
|
|
weight = 1;
|
|
|
|
|
|
|
|
|
|
return weight;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 23:51:59 +02:00
|
|
|
|
void main()
|
|
|
|
|
{
|
2019-05-11 22:11:27 +02:00
|
|
|
|
ivec4 index = ivec4(vBone);
|
|
|
|
|
|
|
|
|
|
vec4 objPos = vec4(vPosition.xyz, 1.0);
|
2019-05-12 02:51:23 +02:00
|
|
|
|
if (vBone.x != -1.0)
|
|
|
|
|
objPos = skin(vPosition, index);
|
|
|
|
|
if(vBone.x != -1.0)
|
|
|
|
|
normal = normalize((skinNRM(vNormal.xyz, index)).xyz);
|
2019-05-11 22:11:27 +02:00
|
|
|
|
|
|
|
|
|
vec4 position = mtxCam * mtxMdl * vec4(objPos.xyz, 1.0);
|
|
|
|
|
|
2019-05-10 23:51:59 +02:00
|
|
|
|
normal = vNormal;
|
|
|
|
|
color = vColor;
|
2019-05-11 22:11:27 +02:00
|
|
|
|
position = objPos;
|
2019-05-12 00:49:32 +02:00
|
|
|
|
f_texcoord0 = vUV0;
|
2019-05-12 01:11:13 +02:00
|
|
|
|
f_texcoord1 = vUV1;
|
|
|
|
|
f_texcoord2 = vUV2;
|
2019-05-10 23:51:59 +02:00
|
|
|
|
|
|
|
|
|
gl_Position = mtxCam * mtxMdl * vec4(vPosition.xyz, 1.0);
|
|
|
|
|
|
2019-05-12 02:51:23 +02:00
|
|
|
|
float totalWeight = BoneWeightDisplay(index);
|
|
|
|
|
boneWeightsColored = BoneWeightColor(totalWeight).rgb;
|
2019-05-10 23:51:59 +02:00
|
|
|
|
|
|
|
|
|
}
|