I find myself in a bit of a predicament and hope that you can assist me. I am working on a VR application where I generate a procedural mesh for a teleportation beam. Currently, I am attempting to stylize the beam using a material and a texture.
In my opinion, my UVs are set correctly, but I have noticed that the texture is mirrored along the X-axis. To address this, I reversed my UV mapping by assigning the last UV coordinates to the first vertex.
Even though I have resolved the issue, I still wonder why the first vertex cannot simply start with the UV coordinates “0,0.” I have even created a sample project with a basic quad mesh that uses a UV mapping checker texture. I have marked the vertices and the negative Z-axis (WorldForward) to better illustrate the situation. The first vertex has UV coordinates “0,0,” and so on – everything becomes clearer when you look at the project.
I know that this fixes it, i wrote:
“In my opinion, my UVs are set correctly, but I have noticed that the texture is mirrored along the X-axis. To address this, I reversed my UV mapping by assigning the last UV coordinates to the first vertex.”
This fixed my problem. But why does it work that way. My first initialised vertex should be my start UV-coordinate (0,0), but i have to initialise it with (0,1). But it doesnt make sense, does it?
Textures are bottom up in memory. So the first byte of the texture memory is the top-left of the image
The UV Coordinates are bottom up. (0,0) is the bottom left of the texture
If you don’t believe me that textures are stored bottom up in OpenGL, look at the documentation for glTexImage2D. It explicitly states that “The first element corresponds to the lower left corner of the texture image”. You can’t get clearer than that.
That’s quite interesting. It probably works the same for WebGL, does it ?