- Home /
What do the letters in stpq stand for? (GLSL)
xyzw, and rgba, I get. What's stpq?? (Yes, I know they're intended for texture coordinates.)
Um, I ask questions almost as much as I answer them, I think! Build knowledge through other people and then share it like they did for you!
I thought I could figure this out with a little research and/or thinking, but it's turned into an unexpectedly entertaining question! Looking forward to seeing other responses.
Since you know stpq are intended for texture coordinates, and you get the "difference" between xyzw and rgba, doesn't it feel like this is just another way of describing texture coords just like you describe colors or positions? :)
Answer by Wolfram · Mar 14, 2011 at 04:12 PM
It's just a convention to be able to address texture coordinates. Generally, you'd only need two or three dimensions. Not sure if a 4th dimension is ever used by anyone - maybe it's just added for completeness, or it might be useful as a time variant component, such as for Perlin noise computation.
Why the letters stpq? Well, a valid question would be, why not uv instead of st? I am not sure which convention came first in the history of texture mapping computer graphics. Nowadays, using uv is generally more common, but st is also still being used.
To be able to access 3D textures you'd need a 3rd dimension. When using uv, the convention suggests to use 'w'. However, this one is already taken as the homogeneous part of the xyzw mapping. stuv or uvst can't be used, since they mean the same thing (s is synonymous to u, and so are t/v), which would cause confusion. So the next available letters backwards in the alphabet are p and q, with xyzw taken, uv blocked, and r taken by the color component.
Hence, stpq. I guess uvpq would have been another valid defintion.
I've NEVER heard of st. Is this really something people do, use .st? It makes a lot more sense to me to just use .xy, given that uv isn't available.
It's used, but imoe uv is generally widely used in computer graphic terms. The reason you probably are more familiar with xyzw is that Unity has Vector classes that expose those members. OpenGL for instance makes use of stpq. http://www.opengl.org/sdk/docs/man/xhtml/glTexCoord.xml DirectX uses the uv?? notation http://msdn.microsoft.com/en-us/library/bb206245(v=vs.85).aspx
It's not from using Unity, at least primarily. It's from using ANY modeling or animation package on the market. Every single one calls them UVs, or UVWs in the case of $$anonymous$$ax.
Ah yes, according to Statement's statement (couldn't resist ;-) ), st is used in both mathematical context, and in the OpenGL specs - I think that's where I remembered it from. However, the OpenGL definition uses strq, which, once again, is not possible here due to the r already being used.
$$anonymous$$aybe we could suggest to have them include uvpq, too :o) since most people associate uv with texture mapping, not st.
Answer by Statement · Mar 14, 2011 at 04:38 PM
I believe it's a common mathematical convention that refer to points in a plane/box/coordinate space(wiki).
...where s and t range over all real numbers, v and w are given vectors defining the plane, and r0 is the vector representing the position of an arbitrary (but fixed) point on the plane.
You can define higher dimensions in the same manner.
Thus, the notation is stpq for points in the texture coordinate set.
Answer by Bampf · Mar 14, 2011 at 04:05 PM
The main thing is that STPQ must avoid reusing letters of the other two (RGBA, XYZW.)
It also suggests that they thought a typical use would be to store a pair of texture coordinates: (ST) and (PQ).
It's interesting that they avoided UV for one of the pairs, even though that's both a time-honored way to refer to 2D texture coordinates, and directly follows ST, e.g. why not UVST?) So it appears to have been deliberate, but I don't know why. (Maybe they wanted to avoid confusion when discussing UV coordinates versus how those coordinates are actually stored in the vector?)
You may have hit the nail on the head in your very last sentence. I think that's why uv was avoided.
Answer by efge · Mar 14, 2011 at 03:19 PM
From The Art of Texturing Using The OpenGL Shading Language:
"... for the sake of code clarity and convention: for a position we will use {xyzw}, {rgba} for a color and {stpq} for texture coordinates."
Edit:
stpq = xyzw = 3 dimensional texture coordinates + inverse scale factor
I think its the part "code clarity and convention" that efge tries to communicate.
I think you should use rgba when dealing with color values, xyzw when dealing with positions and stpq when dealing with texture coordinates. Following the convention it becomes immediately clear whether the values are considered to be used as a color or a coordinate.
I'll do that when they rewrite GLSL to look like anything anybody uses to create 3D content. :-P
Answer by Martin-Kraus · Aug 13, 2011 at 09:12 AM
As far as I know s, t, r, q have been the official OpenGL texture coordinates from the beginning (i.e. back in the early 1990s). (I'm not sure when they switched to s, t, p, q. But you can probably find out by going through the specs.) The first version of the OpenGL Programming Guide explains (see http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html ):
"Texture coordinates can comprise one, two, three, or four coordinates. They're usually referred to as the s, t, r, and q coordinates to distinguish them from object coordinates (x, y, z, and w) and from evaluator coordinates (u and v; see Chapter 11 ). For one-dimensional textures, you use the s coordinate; for two-dimensional textures, you use s and t. Currently, the r coordinate is ignored (although it might have meaning in the future)."
I assume the reason for "s" is that "s" is often used to identify a "scalar", i.e. a one-dimensional number. "t" is just the next letter in the alphabet. They couldn't continue with "u" and "w" because they used those for evaluator coordinates; thus, they used the letters before. "q" being somewhat more exotic as a variable ("r" is very often used in mathematics as the "radius" or generally a point in spherical or polar coordinates), thus, the fourth coordinate was named "q". You might also notice that they use all the letters at the end of the alphabet for such coordinates (q, r, s, t, u, v, w, x, y, z).
Of course, later they found out that "r" conflicts with the "r" in RGBA and therefore switched to "p".
Animation tools would use "t" for time and therefore wouldn't use "s" and "t" for texture coordinates. Thus, they used "u" and "v" because they didn't care about evaluators. (Those are used to describe parametric surfaces such as spline patches. However, evaluators where never implemented in commercial hardware (as far as I know) and therefore were dropped from OpenGL at some point.)
Your answer
Follow this Question
Related Questions
converting HLSL to GLSL. 0 Answers
iPhone: Use of undeclared identifier '_patchFragColor' 1 Answer
GLSL error 1 Answer
Is it possible to dynamically recompile a shader on-the-fly? 1 Answer
Awesome Bump shader in Unty? 0 Answers