negative UV coordinates ?

Blitz3D Forums/Blitz3D Programming/negative UV coordinates ?

RemiD(Posted 2015) [#1]
Hello,

I was not aware about this being possible before today... I thought that UV coordinates are always between 0.0 and 1.0... But apparently there can be negative UV coordinates between 0.0 and -1.0...

Can somebody explains what this means ? Does this mean that the texture is flipped on the Xaxis or on the Yaxis ?


Bobysait(Posted 2015) [#2]
UV coordinates are just coordinates, you can set whatever you want. {-1.0,0.0} ... or {-60000.0,33333}

it sets the canvas aspect for the triangle to be rendered, mixed with the texture matrix (tex origin + tex scale + tex rotation) you can stretch the texture area as you need.

But to be clear, using negative UVs is not that usefull, as long as {-1.0,0.0} is the same as {1.0,0.0} because the UVs coordinates are modulated to fit the texture area. And the texture area is within 0.0,1.0.
The only difference you could see would happen if you set the texture flag to 16 and/or 32 (which clamp the area of the texture ... but I'm not sure if it clamps the texture matrix before or after being transformed by the vertex UVs).

So, to answer your question :
Yes, it does actually flip the area ... but you could also invert your vertex UVs to get the same result

for exemple, this is a simple quad with standard UVs
AddVertex(surface, -1,+1,0, 0,0)
AddVertex(surface, +1,+1,0, 1,0)
AddVertex(surface, +1,-1,0, 1,1)
AddVertex(surface, -1,-1,0, 0,1)

this is the same quad with texture flip horizontally.
AddVertex(surface, -1,+1,0, 0,0)
AddVertex(surface, +1,+1,0, -1,0)
AddVertex(surface, +1,-1,0, -1,1)
AddVertex(surface, -1,-1,0, 0,1)

And this does exactly the same
AddVertex(surface, -1,+1,0, 1,0)
AddVertex(surface, +1,+1,0, 0,0)
AddVertex(surface, +1,-1,0, 0,1)
AddVertex(surface, -1,-1,0, 1,1)


RemiD(Posted 2015) [#3]
Ok, thanks for the explanations.

I have noticed this because i was trying to create a texture atlas (a big texture containing several small textures) and the uvmaping was all corrupted so i tried to debug the U,V values and i have noticed there were some negative values...
This is bad news, it means that i won't be able to use my method to create a texture atlas...
I will have to find another way to combine textures and surfaces... This is not urgent anyway.


Kryzon(Posted 2015) [#4]
The low level control of this is with the graphics APIs.
Direct3D and OpenGL allow you to set how you want the UV values to be interpreted. I think this is called "addressing mode", and it's a setting of the texture sampler (the part of logic that grabs pixels from textures).

- D3DTEXTUREADDRESS enumeration

- glTexParameter function