PDA

View Full Version : What are the exact right texture coordinates?

Dylan
05-15-2007, 11:57 PM
Hi, I have a very basic question, but I am breaking my head over it.

an example: I have a 4x4 2D texture, it uses linear interpolation. MY question is, how do i get closest to the original values that i have stored in the texture?

What coordinates do I use, the texture ranges from 0.0 to 1.0? in 1D case which of these 4 possibilities is the right array to use?
- (0.0),(0.25),(0.50),(0.75) or
- (0.25),(0.50),(0.75),(1.0) or
- (0.125),(0.375),(0.625),(0.875) or
- (0.0),(0.333),(0.667),(1.0)

yes, i am aware of the fact that u can use NEAREST, but I need to use linear and i want to know where in the texture the exact value is located. Please enlighten me :)

Bob
05-16-2007, 01:04 AM
|--x--|--x--|--x--|--x--|
0 1| are texel boundaries, x texel centers where the texel color is defined, and the number below are the texture cooridnates; 0 to the left and 1 to the right.

To to sample exactly where the texel color is defined, you sample at (0.1250, 0.3750, 0.6250, 0.8750). In general, for a texture with N texels (along a specific dimension), the n:th texel (counting from zero) is located at (n+0.5)/N.

Also, keep in mind that these are not the texture coorinates you should use for, say, a screen aligned quad to get a 1 to 1 mapping of screen- and vertex coordinates and texels to perfectly render an image for example.

Dylan
05-16-2007, 01:23 AM
Originally posted by Bob:
[CODE]

Also, keep in mind that these are not the texture coorinates you should use for, say, a screen aligned quad to get a 1 to 1 mapping of screen- and vertex coordinates and texels to perfectly render an image for example. thanks for your quick reply!

I will also render a screen aligned quad with NEAREST, what coordinates should I use then?

Relic
05-16-2007, 02:31 AM
http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=015161#000003

ZbuffeR
05-16-2007, 04:52 AM
(0.125),(0.375),(0.625),(0.875)

Why ?

0-------1
|.|.|.|.|. is a texel
| is the edge between two texels.

EDIT: ok, I am slower than everybody else :)

oc2k1
05-16-2007, 05:54 AM
It's depend of the Clamping mode. for Clamp to Edge it's:

x--|--x--|--x--|--x
0 1

Bob
05-16-2007, 07:12 AM
Originally posted by oc2k1:
It's depend of the Clamping mode. for Clamp to Edge it's:

x--|--x--|--x--|--x
0 1No, the coordinates needed to hit the defined colors are still the same. Clamp to edge makes the coordinate clamp to the range [0.125, 0.875] instead of [0, 1]. Whatever clamping mode, 0.125 is the coordinate needed to hit the center of the first texel.