ADD: vertex small fix

This commit is contained in:
2025-12-03 15:00:19 +09:00
parent f152f26cd1
commit 01b28174be
3 changed files with 30 additions and 10 deletions

View File

@@ -37,15 +37,19 @@ void main()
{ {
Vertex v = PushConstants.vertexBuffer.vertices[gl_VertexIndex]; Vertex v = PushConstants.vertexBuffer.vertices[gl_VertexIndex];
vec4 worldPos = PushConstants.render_matrix * vec4(v.position, 1.0f); mat3 M = mat3(PushConstants.render_matrix);
mat3 normalMatrix = transpose(inverse(M));
vec4 worldPos = PushConstants.render_matrix * vec4(v.position, 1.0);
gl_Position = sceneData.viewproj * worldPos; gl_Position = sceneData.viewproj * worldPos;
outNormal = (PushConstants.render_matrix * vec4(v.normal, 0.f)).xyz; outNormal = normalize(normalMatrix * v.normal);
vec3 worldTangent = (PushConstants.render_matrix * vec4(v.tangent.xyz, 0.f)).xyz;
outTangent = vec4(normalize(worldTangent), v.tangent.w); vec3 worldTangent = normalize(normalMatrix * v.tangent.xyz);
// Pass pure vertex color; apply baseColorFactor only in fragment outTangent = vec4(worldTangent, v.tangent.w);
outColor = v.color.xyz; outColor = v.color.xyz;
outUV.x = v.uv_x; outUV = vec2(v.uv_x, v.uv_y);
outUV.y = v.uv_y;
outWorldPos = worldPos.xyz; outWorldPos = worldPos.xyz;
} }

View File

@@ -612,8 +612,24 @@ std::optional<std::shared_ptr<LoadedGLTF> > loadGltf(VulkanEngine *engine, std::
}); });
} }
// Generate tangents if missing and we have UVs // Generate tangents only when needed for normal mapping.
if (!hasTangents) // If the bound material has no normal map, we can skip TBN generation.
bool materialHasNormalMap = false;
if (p.materialIndex.has_value())
{
size_t matIndex = p.materialIndex.value();
if (matIndex < gltf.materials.size())
{
materialHasNormalMap = gltf.materials[matIndex].normalTexture.has_value();
}
}
else if (!gltf.materials.empty())
{
// Primitives without an explicit material fall back to material 0.
materialHasNormalMap = gltf.materials[0].normalTexture.has_value();
}
if (!hasTangents && materialHasNormalMap)
{ {
size_t primIndexStart = newSurface.startIndex; size_t primIndexStart = newSurface.startIndex;
size_t primIndexCount = newSurface.count; size_t primIndexCount = newSurface.count;

View File

@@ -10,7 +10,7 @@ except Exception:
DEFAULT_SUFFIX = { DEFAULT_SUFFIX = {
"albedo": ["_albedo", "_basecolor", "_base_colour", "_base_color", "_base", "baseColor", "BaseColor"], "albedo": ["_albedo", "_basecolor", "_base_colour", "_base_color", "_base", "baseColor", "BaseColor"],
"mr": ["_mr", "_orm", "_metalrough", "_metallicroughness", "metallicRoughness", "Metallic"], "mr": ["_mr", "_orm", "_metalrough", "_metallicroughness", "metallicRoughness", "Metallic", "Metalness"],
"normal": ["_normal", "_norm", "_nrm", "_normalgl", "Normal"], "normal": ["_normal", "_norm", "_nrm", "_normalgl", "Normal"],
"occlusion": ["_occlusion", "_occ", "_ao"], "occlusion": ["_occlusion", "_occ", "_ao"],
"emissive": ["_emissive", "_emission", "_emit"], "emissive": ["_emissive", "_emission", "_emit"],