**0**

# A small trick not mentioned by the book

Started by NEXUSKill, Jan 26 2011 10:08 AM

6 replies to this topic

###
#1
Members - Reputation: **475**

Posted 26 January 2011 - 10:08 AM

For those who don't know this already, texture coordinates are not limited to be between 0 and 1, they actually can be set to any real number between -n and +n, if you set for instance, the vertices that have a 1 value in one of their texture coordinates (usually referred to as UV coordinates) to a value of 2, you'll see that the texture gets tiled twice per axis, play around with this values, some nice tricks can be achieved by using this functionality.

Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272

###
#2
Members - Reputation: **1814**

Posted 26 January 2011 - 10:24 AM

This depends on how they work (can't think of the term off the top of my head). You can set this to act in different ways. Sometimes you get the pixels on the edge repeated from 1 to n (clamp). Othertimes it tiles as you have stated. Theres also a mirrored one too (where as it goes onward to 2, the texture goes back to 0, then back to 1 as it gets to 3 and so on). Of course in a pixel shader its different.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store:

###
#5
Members - Reputation: **475**

Posted 27 January 2011 - 01:14 PM

So if i had a texture with an X on it, set the coordinate to 2, it's show up with two X's?

If you had a rectangle as the ones defined in the book sample, and put the larger values of texture coordinates to 2 in one axis you would see two X images compressed within the same rectangle, if you were to set both axis max values to 2, you would see four X within the same rectangle compressed and tiled together.

Best way to understand how texture wrapping works is to fool around with the UV values, try different things, negative values, decimal values, going from 1 to 0 instead of 0 to 1, play with it and it will become much clearer than anyone could explain with words, and in less time too.

Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272

###
#7
Members - Reputation: **475**

Posted 27 January 2011 - 01:30 PM

Perhaps to better understand it you should know what the graphic API does when applying a texture in a polygon.

The values of UV coordinates in the vertices state the position in that exact point, everything in between is linearly interpolated, if we are half way between two vertices, the texture coordinates should be half way between the two values stated at each verices, if the vertices have 0 and 1 as coordinates each, half way is 0.5, if one vertex had 0 and the other had 0.75, the texture coordinate for a pixel that is half way between the two vertices would be 0.375

The values of UV coordinates in the vertices state the position in that exact point, everything in between is linearly interpolated, if we are half way between two vertices, the texture coordinates should be half way between the two values stated at each verices, if the vertices have 0 and 1 as coordinates each, half way is 0.5, if one vertex had 0 and the other had 0.75, the texture coordinate for a pixel that is half way between the two vertices would be 0.375

Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272