yigitEmre
yigitEmre

Reputation: 101

Vulkan Wierd Texture Coordinate

To test my renderer, I just render a quad that fills the screen to texture sampling These are my vertex inputs in input assembly. enter image description here

The problem is that I rendered texture coordinates to screen and I saw that they are interpolated wrong like they start half of the texture(like 0.5..) and end at 0.8.. coord etc. These are my shaders and their compiled version by glslc.exe

Vertex Shader

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

Fragment Shader

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

Compiled versions

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

Upvotes: 1

Views: 39

Answers (1)

yigitEmre
yigitEmre

Reputation: 101

It is silly that I didn't notice it earlier. The problem is the result of later-added projection. It actually renders the quad almost twice size of the screen.

Upvotes: 0

Related Questions