stuff
This commit is contained in:
+48
-15
@@ -8,27 +8,60 @@ layout (location = 4) in vec4 weights;
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoord;
|
||||
out vec4 FragPosLightSpace;
|
||||
|
||||
uniform mat4 proj;
|
||||
uniform mat4 view;
|
||||
uniform mat4 modl;
|
||||
uniform mat4 lightSpaceMatrix;
|
||||
uniform mat4 finalBonesMatrices[100];
|
||||
|
||||
const int MAX_BONES = 100;
|
||||
const int MAX_BONE_INFLUENCE = 4;
|
||||
uniform mat4 finalBonesMatrices[MAX_BONES];
|
||||
|
||||
uniform int uvMode = 0; // 0 = stretch, 1 = tile
|
||||
uniform vec3 tileScale = vec3(1.0);
|
||||
uniform vec2 uvOffset = vec2(0.0);
|
||||
|
||||
// Same direction as transpose(inverse(m)) for normals, without the per vertex inverse
|
||||
mat3 CofactorMatrix(mat3 m)
|
||||
{
|
||||
return mat3(cross(m[1], m[2]), cross(m[2], m[0]), cross(m[0], m[1]));
|
||||
}
|
||||
|
||||
// Tiling ignores the mesh's uvs and projects from whichever axis the surface faces.
|
||||
// Done on the bind pose, so the pattern stays stuck to the character as it moves.
|
||||
vec2 SurfaceUV()
|
||||
{
|
||||
if (uvMode == 0) return aTexCoord + uvOffset;
|
||||
|
||||
vec3 n = abs(aNormal);
|
||||
vec3 p = aPos * tileScale;
|
||||
if (n.y >= n.x && n.y >= n.z) return p.xz + uvOffset;
|
||||
if (n.x >= n.z) return p.zy + uvOffset;
|
||||
return p.xy + uvOffset;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 boneTransform = finalBonesMatrices[boneIds[0]] * weights[0];
|
||||
boneTransform += finalBonesMatrices[boneIds[1]] * weights[1];
|
||||
boneTransform += finalBonesMatrices[boneIds[2]] * weights[2];
|
||||
boneTransform += finalBonesMatrices[boneIds[3]] * weights[3];
|
||||
vec4 totalPosition = vec4(0.0);
|
||||
vec3 totalNormal = vec3(0.0);
|
||||
|
||||
vec4 localPos = boneTransform * vec4(aPos, 1.0);
|
||||
vec4 worldPos = modl * localPos;
|
||||
for (int i = 0; i < MAX_BONE_INFLUENCE; i++)
|
||||
{
|
||||
if (boneIds[i] == -1) continue;
|
||||
if (boneIds[i] >= MAX_BONES)
|
||||
{
|
||||
totalPosition = vec4(aPos, 1.0);
|
||||
totalNormal = aNormal;
|
||||
break;
|
||||
}
|
||||
totalPosition += (finalBonesMatrices[boneIds[i]] * vec4(aPos, 1.0)) * weights[i];
|
||||
totalNormal += mat3(finalBonesMatrices[boneIds[i]]) * aNormal * weights[i];
|
||||
}
|
||||
|
||||
FragPos = worldPos.xyz;
|
||||
Normal = normalize(mat3(transpose(inverse(modl * boneTransform))) * aNormal);
|
||||
TexCoord = aTexCoord;
|
||||
FragPosLightSpace = lightSpaceMatrix * worldPos;
|
||||
gl_Position = proj * view * worldPos;
|
||||
}
|
||||
vec4 worldPos = modl * totalPosition;
|
||||
|
||||
FragPos = worldPos.xyz;
|
||||
Normal = normalize(CofactorMatrix(mat3(modl)) * totalNormal);
|
||||
TexCoord = SurfaceUV();
|
||||
gl_Position = proj * view * worldPos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user