Vulkan 奇怪的纹理坐标

问题描述 投票:0回答:1

为了测试我的渲染器,我只渲染一个填充屏幕的四边形以进行纹理采样这些是我在输入组件中的顶点输入。 enter image description here

问题是我将纹理坐标渲染到屏幕上,我发现它们插值错误,就像它们从纹理的一半(如 0.5..)开始并以 0.8.. 坐标结束等。这些是我的着色器及其编译版本glslc.exe

顶点着色器

#version 450

layout(location = 0) in vec2 positions;
layout(location = 1) in vec3 colors;
layout(location = 2) in vec2 texCoords;

layout(location = 0) out vec4 color;
layout(location = 1) out vec2 texCoord;

layout(push_constant) uniform PushConstants {
    vec2 projection;
} pushConstants;


void main() 
{
    if(colors.r == 0.0 && colors.g == 0.0 && colors.b == 0.0) 
        color = vec4(colors, 0.0);
    else
        color = vec4(colors, 1.0);

    texCoord = texCoords;
    gl_Position = vec4(positions * pushConstants.projection, 0.0, 1.0);
}

片段着色器

#version 450

layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 color;
layout(location = 1) in vec2 texCoord;

layout(input_attachment_index = 0, binding = 0) uniform subpassInput offScreenInput;
layout(binding = 1) uniform sampler2D textureSampler;

void main() 
{
    //FragColor = subpassLoad(offScreenInput) * (1.0 - color.a) + texture(textureSampler, texCoord).r * color;
    FragColor = vec4(texCoord.x, texCoord.y, 0.0, 1.0);
}

编译版本

#version 460

layout(push_constant, std430) uniform PushConstants
{
    vec2 projection;
} pushConstants;

layout(location = 1) in vec3 colors;
layout(location = 0) out vec4 color;
layout(location = 1) out vec2 texCoord;
layout(location = 2) in vec2 texCoords;
layout(location = 0) in vec2 positions;

void main()
{
    bool _17 = colors.x == 0.0;
    bool _24;
    if (_17)
    {
        _24 = colors.y == 0.0;
    }
    else
    {
        _24 = _17;
    }
    bool _31;
    if (_24)
    {
        _31 = colors.z == 0.0;
    }
    else
    {
        _31 = _24;
    }
    if (_31)
    {
        color = vec4(colors, 0.0);
    }
    else
    {
        color = vec4(colors, 1.0);
    }
    texCoord = texCoords;
    gl_Position = vec4(positions * pushConstants.projection, 0.0, 1.0);
}

#version 460

layout(input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput offScreenInput;
layout(set = 0, binding = 1) uniform sampler2D textureSampler;

layout(location = 0) out vec4 FragColor;
layout(location = 1) in vec2 texCoord;
layout(location = 0) in vec4 color;

void main()
{
    FragColor = vec4(texCoord.x, texCoord.y, 0.0, 1.0);
}
shader interpolation fragment-shader texture-mapping
1个回答
0
投票

真是愚蠢,我没有早点注意到这一点。问题是后来添加的投影的结果。它实际上渲染了四边形几乎是屏幕大小的两倍。

© www.soinside.com 2019 - 2024. All rights reserved.