This commit is contained in:
2026-11-02 19:35:36 -05:00
parent a6103e453d
commit 7b32ad674e
52 changed files with 3285 additions and 1488 deletions
+30 -6
View File
@@ -20,7 +20,30 @@ out vec3 normal;
out vec2 texCoord;
out vec3 FragPos;
out vec4 fragposlightspace;
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 tex + uvOffset;
vec3 n = abs(norm);
vec3 p = pos * 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()
{
vec4 totalPosition = vec4(0.0);
@@ -40,9 +63,10 @@ void main()
totalPosition += (finalBonesMatrices[boneIds[i]] * vec4(pos, 1.0))* weights[i];
totalNormal += mat3(finalBonesMatrices[boneIds[i]]) * norm * weights[i];
}
FragPos = vec3(modl * totalPosition);
fragposlightspace = lightSpaceMatrix * vec4(FragPos, 1.0);
gl_Position = proj * view * modl * totalPosition;
normal = normalize(mat3(transpose(inverse(modl))) * totalNormal);
texCoord = tex;
vec4 worldPos = modl * totalPosition;
FragPos = worldPos.xyz;
fragposlightspace = lightSpaceMatrix * worldPos;
gl_Position = proj * view * worldPos;
normal = normalize(CofactorMatrix(mat3(modl)) * totalNormal);
texCoord = SurfaceUV();
}