gpt4 book ai didi

textures - Vulkan 纹理模糊问题

转载 作者:行者123 更新时间:2023-12-03 22:21:26 34 4
gpt4 key购买 nike

我有一个简单的 Vulkan 设置,它加载了一个相当大的网格文件(女性)并应用了漫反射和法线贴图纹理。

顶点着色器:

#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);
}

片段着色器:
#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)
}

结果:
enter image description here

可以看出,整个网格上的碎片阴影有点模糊和嘈杂,特别是在 ARM 上。

每当我加载这个网格时 具有相同的纹理在 Unity3D 中,结果没有提到的噪音:
enter image description here

另一个带有法线贴图 + 规范贴图的模型效果很好,所以这对我来说听起来很矛盾,因为 Unity3D 可以正确渲染这三个模型,但是我的程序无法仅为特定模型生成照明值,这意味着着色器可以解释纹理/模型中的数据!
enter image description here

这个问题的根源是什么?

[更新]

使用几何着色器可视化法线后:
enter image description here

最佳答案

你对法线(以及其他潜在的)的转换在我看来是错误的。您通常不会使用与顶点相同的矩阵进行变换。通常使用逆转置。

尝试使用例如可视化您的法线使用几何着色器(发射线)。

关于textures - Vulkan 纹理模糊问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47366621/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com