Vulcan texture fuzzy problem

I have a simple Vulkan installation that downloads a fairly large grid file (female) and also applies diffuse and normal map textures.

Vertex Shader:

#version 450 core layout (set = 0, binding = 0) uniform ModelMatrix { mat4 model; } modelMatrix; layout (push_constant) uniform ViewProjection { mat4 view; mat4 projection; } viewProjection; layout (location = 0) in vec3 inPos; layout (location = 1) in vec3 inNor; layout (location = 2) in vec2 inUV; layout (location = 3) in vec3 inTan; layout (location = 4) in vec3 inBitan; layout (location = 0) out vec3 fragPos; layout (location = 1) out vec2 fragUV; layout (location = 2) out vec3 fragNor; layout (location = 3) out vec3 fragTan; layout (location = 4) out vec3 fragBitan; void main() { fragPos = vec3(viewProjection.view * modelMatrix.model * vec4(inPos, 1.0)); fragNor = mat3(viewProjection.view * modelMatrix.model) * inNor; fragUV = inUV; fragTan = mat3(viewProjection.view * modelMatrix.model) * inTan; fragBitan = mat3(viewProjection.view * modelMatrix.model) * inBitan; gl_Position = viewProjection.projection * vec4(fragPos, 1.0); } 

Fragment Shader:

 #version 450 core layout (location = 0) in vec3 fragPos; layout (location = 1) in vec2 fragUV; layout (location = 2) in vec3 fragNor; layout (location = 3) in vec3 fragTan; layout (location = 4) in vec3 fragBitan; layout (location = 0) out vec4 outFragColor; layout (set = 0, binding = 0) uniform MVP { mat4 model; } mvp; layout (set = 0, binding = 1) uniform sampler2D textureSampler; layout (set = 0, binding = 2) uniform sampler2D normalSampler; layout (set = 0, binding = 3) uniform sampler2D specSampler; layout (push_constant) uniform VP { mat4 view; mat4 projection; } vp; const vec3 lightPos = vec3(0.0, 0.0, 300.0); const float lightIntensity = 1.0f; const float shininess = 50.0; void main() { mat3 TBN = transpose(mat3( fragTan, fragBitan, fragNor )); vec3 normapFragNor = normalize(texture(normalSampler, fragUV).rgb * 2.0 - 1.0); vec3 lightDirectionTangSpace = TBN * (lightPos - fragPos); float dotProduct = dot(normalize(lightDirectionTangSpace), normalize(normapFragNor)); float meshNormalDotProduct = dot(normalize(lightDirectionTangSpace), normalize(fragNor)); float diffuse = min(max(dotProduct, 0.0), 1.0); float specular = pow(diffuse, shininess); vec4 texelColor = texture(textureSampler, fragUV); vec3 specularColor = vec3(texture(specSampler, fragUV)); float specResultColorComponent = min(1.0, diffuse); outFragColor = vec4(diffuse * vec3(texelColor) , texelColor.a); // For Spec Map: diffuse * vec3(texelColor) + (specular * specularColor) } 

Result: enter image description here

As you can see, the fragments on the entire grid are shaded a bit fuzzy and noisy, especially on the hands.

Whenever I load this mesh with the same textures into Unity3D, the result without the mentioned noise: enter image description here

Another model with a normal map + spec works like a charm, so it sounds paradoxical for me, since Unity3D can correctly display both of these models, but my program cannot generate lighting values ​​only for a specific model, which implies that the shader can interpret the data in textures / patterns! enter image description here

What could be the source of this problem?

[UPDATE]

After visualizing normals with a geometric shader: enter image description here

+5
source share
1 answer

Your transformations of normals (and potential others) seem to me wrong. Usually you will not transform using the same matrix as the vertex. Inverse transposition is usually used.

Try visualizing your normals, for example. using a geometric shader (emit lines).

+2
source

Source: https://habr.com/ru/post/1273491/


All Articles