Hi. I tried to find the specification on Vulkan Texture Coordinate.
I think the specification is not clear.
At first, I tried to look over the latest specification of Vulkan 1.1, here.
https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#_image_operations_overview
Chapter 15.1 is “Image Operations Overview”, and it has 15.1.1 “Texel Coordinate System” part.
the spec said that
"
Normalized texel coordinates:
- The s coordinate goes from 0.0 to 1.0.
- The t coordinate goes from 0.0 to 1.0.
"
it does not specify the origin of the texture coordinate. I mean the direction of ‘s’ and ‘t’.
the graph in the part shows the arrow direction.
However, When I found the old specification of Vulkan
https://vulkan.lunarg.com/doc/view/1.0.37.0/linux/vkspec.chunked/ch15s01.html
it does specify the directions like :
"
Normalized texel coordinates:
- The s coordinate goes from 0.0 to 1.0, left to right.
- The t coordinate goes from 0.0 to 1.0, top to bottom.
"
and the graph shows the arrows of ‘t’ coordinate with the inverted direction compared to 1.1 spec.
So, This make me confused with texture coordinate.
I experimented my vulkan application to verify the texture coordinate by myself.
I found The result is the texture coordinate origin of the Vulkan is Top-left.
s coordinate goes from 0.0 to 1.0, left to right
t coordinate goes from 0.0 to 1.0, top to bottom.
the experiment consists of a simple offscreen rendering and swap chain buffer with screen quad.
I construct the positions and texture coordinate of the screen quad based on GL coordinates like:
float vertices[] =
{
// positions texCoords
-1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f, 0.0f,
};
uint16 indices[] =
{
0, 1, 2,
2, 1, 3
};
and the vulkan vertex shader is…
#version 310 es
precision mediump float;
// Screen Quad Vertex Shader
layout (location = 0) in vec2 a_Position;
layout (location = 1) in vec2 a_TexCoord;
layout (location = 0) out vec2 v_TexCoord;
void main()
{
gl_Position = vec4(a_Position.x, a_Position.y, 0.0, 1.0);
gl_Position.y = -gl_Position.y;
gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;
v_TexCoord = a_TexCoord;
// When I comment out this line, the offscreen texture become upside down
v_TexCoord.y = 1.0 - v_TexCoord.y;
}
So, I have questions…:
- Is the texture coordinate which i found with my experiment right?
- If so, why does the spec 1.1 show upward ‘t’ coordinate direction?
I always appreciate the ones who help me…
Thanks!