I've seen the term st come up a few times when looking at other OpenGL fragment shaders. However, I don't know what it stands for or what it's used for. Here's an example:

uniform vec2 u_resolution;

vec2 st = gl_FragCoord.xy/u_resolution;

I can understand that this is converting the pixel coordinates into normalized coordinates of 0.0 - 1.0 instead of 640 x 480 (for example).

I've also seen things like position.st.

What does it mean?


The common names for the components of texture coordinates are U and V. However, because the next letter used (for 3D textures) is W, that causes a conflict with the names for the components of a position: X, Y, Z, and W.

To avoid such conflicts, OpenGL's convention is that the components of texture coordinates are named S, T, and R. Thus, you have function calls like this:

glTexParameter(..., GL_TEXTURE_WRAP_S, GL_REPEAT);

Where GL_TEXTURE_WRAP_S refers to wrapping in the S component of the texture coordinate.

Unfortunately, OpenGL picked S, T, and R long before GLSL and swizzle masks came around. R, of course, conflicts with R, G, B, and A. To avoid such conflicts, in GLSL, the texture coordinate swizzle mask uses S, T, P, and Q.

In GLSL, you can swizzle with XYZW, STPQ, or RGBA. They all mean exactly the same thing. So position.st is exactly the same as position.xy. However, you're not allowed to combine swizzle masks from different sets. So position.xt is not allowed.

  • $\begingroup$ LOL What a mess ! $\endgroup$ – Michael Dec 9 '20 at 3:46
  • $\begingroup$ @Michael: What's "mess"y about it? $\endgroup$ – Nicol Bolas Dec 9 '20 at 5:11
  • $\begingroup$ The way they name everything. I was so confused until I saw your answer. $\endgroup$ – Michael Dec 9 '20 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.