Vulkan渲染器纹理坐标插值异常问题求助
Vulkan渲染器全屏四边形纹理坐标插值异常问题
我在测试自研Vulkan渲染器时,绘制了一个全屏四边形用于纹理采样,输入装配阶段的顶点输入如图所示。但将纹理坐标渲染到屏幕后,发现插值异常——起始值约为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); }
glslc.exe编译后版本
#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); }
内容的提问来源于stack exchange,提问作者yigitEmre
相关产品推荐
相关产品推荐

