ADD: KTX loader completed

This commit is contained in:
2025-11-10 18:30:14 +09:00
parent 8f340ec08a
commit 50f1503f09
9 changed files with 152 additions and 320 deletions

View File

@@ -22,10 +22,13 @@ void main() {
float metallic = clamp(mrTex.y * materialData.metal_rough_factors.x, 0.0, 1.0);
// Normal mapping: decode tangent-space normal and transform to world space
// Expect UNORM normal map (not sRGB). Flat fallback is (0.5, 0.5, 1.0).
vec3 Nm = texture(normalMap, inUV).xyz * 2.0 - 1.0;
// Expect UNORM normal map; support BC5 (RG) by reconstructing Z from XY.
vec2 enc = texture(normalMap, inUV).xy * 2.0 - 1.0;
float normalScale = max(materialData.extra[0].x, 0.0);
Nm.xy *= normalScale;
enc *= normalScale;
float z2 = 1.0 - dot(enc, enc);
float nz = z2 > 0.0 ? sqrt(z2) : 0.0;
vec3 Nm = vec3(enc, nz);
vec3 N = normalize(inNormal);
vec3 T = normalize(inTangent.xyz);
vec3 B = normalize(cross(N, T)) * inTangent.w;

View File

@@ -59,9 +59,13 @@ void main()
float metallic = clamp(mrTex.y * materialData.metal_rough_factors.x, 0.0, 1.0);
// Normal mapping path for forward/transparent pipeline
vec3 Nm = texture(normalMap, inUV).xyz * 2.0 - 1.0;
// Expect UNORM normal map; support BC5 (RG) by reconstructing Z from XY.
vec2 enc = texture(normalMap, inUV).xy * 2.0 - 1.0;
float normalScale = max(materialData.extra[0].x, 0.0);
Nm.xy *= normalScale;
enc *= normalScale;
float z2 = 1.0 - dot(enc, enc);
float nz = z2 > 0.0 ? sqrt(z2) : 0.0;
vec3 Nm = vec3(enc, nz);
vec3 Nn = normalize(inNormal);
vec3 T = normalize(inTangent.xyz);
vec3 B = normalize(cross(Nn, T)) * inTangent.w;