I'm finding myself a bit lost amongst the many many sign and domain conventions used in webGl. Take a gander at this regl example (it shows the baboon test image). Here's what I understand of it:
- No primitive is specified; It likely infers
GL_TRIANGLE
. - As such, it creates a single triangular surface with vertices
(-2, 0)
,(0, -2)
,(2, 2)
in world-space. Drawing this out on paper, it appears this was chosen specifically because it encompasses the region[0,1] x [0,1]
. uv
takes its values from world space, including this[0,1] x [0,1]
region (which is the domain oftexture2d
). If I understand correctly, the convention is that+u
points towards the right edge of the image,+v
points towards the top.gl_Position
is set to1 - 2*uv
, so that the image occupies[-1,1] x [-1,1], z=0
in "clip space," whatever that is.- More importantly, it also means that the
+{u,v}
directions correspond to-{x,y}
! - The displayed image, is, in fact, mirrored horizontally!! (compare to this) But it is not mirrored vertically. There must be something else along the eventual conversion to/from onscreen pixel coordinates that cancels out the negative factor in y.
- However, Google searches bring up no evidence that
gl_Position
is mirrored in any way relative to the screen. I see discussion that it is left-handed, but that is simply from negatingz
relative to world coordinates. (e.g. this question here)
In brief, it appears to me that this image ought to be mirrored vertically as well.
What am I missing?
For posterity, the code is reproduced below: (MIT licensed)
const regl = require('regl')()
const baboon = require('baboon-image')
regl({
frag: `
precision mediump float;
uniform sampler2D texture;
varying vec2 uv;
void main () {
gl_FragColor = texture2D(texture, uv);
}`,
vert: `
precision mediump float;
attribute vec2 position;
varying vec2 uv;
void main () {
uv = position;
gl_Position = vec4(1.0 - 2.0 * position, 0, 1);
}`,
attributes: {
position: [
-2, 0,
0, -2,
2, 2]
},
uniforms: {
texture: regl.texture(baboon)
},
count: 3
})()