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
+29 -5
View File
@@ -13,11 +13,35 @@ uniform mat4 proj;
uniform mat4 lightSpaceMatrix;
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,
// so every face of a stretched cube repeats at the same size
vec2 SurfaceUV()
{
if (uvMode == 0) return aTex + 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()
{
FragPos = vec3(modl * vec4(aPos, 1.0));
normal = transpose(inverse(mat3(modl))) * aNormal;
texCoord = aTex;
fragposlightspace = lightSpaceMatrix * vec4(FragPos, 1.0);
gl_Position = proj* view * modl * vec4(aPos,1.0f);
vec4 worldPos = modl * vec4(aPos, 1.0);
FragPos = worldPos.xyz;
normal = CofactorMatrix(mat3(modl)) * aNormal;
texCoord = SurfaceUV();
fragposlightspace = lightSpaceMatrix * worldPos;
gl_Position = proj * view * worldPos;
}