View Full Version : 3d texture r coordinate
06-14-2005, 12:44 AM
hello when use 3d texture , how to fix on the r coordinate ? eg 4*4*4 ,the r coordinate is between 0 to 1 ,if 1/4 ,can get five coordinate of 0.0,0.25,0.5,0.75,1.0,then if slices in r direction is 4,what is the r coordinat of every slice? thank you very much
06-14-2005, 03:16 AM
Each texel occupies the space of a cube with 1/4 length. If you want to hit the texel exactly, you must "aim" in the center of that cube.
06-14-2005, 05:38 PM
thank you very much!i still has a question:why it is not like this?
also "aim" in the center of that cube,and occupies the space of a cube with1/4?
06-15-2005, 12:30 AM
I'm assuming that you assign the same texture r coordinate to all vertices to single out a slice of the 3D texture.
Actually it's the same for s, t and r texture coordinates. An exact hit on a texel is always achieved with a texture coordinate of (2*n+1)/(2*m) where n is the texel you wish to hit and m is the size of the texture in that dimension.
However, if you use different texture coordinates per vertex, texcoord interpolation (which is evaluated at pixel centers in the same fashion) will just do this for you and you won't notice.
Consider a two-by-one-pixel quad with an equally sized texture mapped onto it.
glTexCoord2f(0.0f,0.0f); glVertex2f(0.0f,0.0f); //A
glTexCoord2f(1.0f,0.0f); glVertex2f(2.0f,0.0f); //B
glTexCoord2f(1.0f,1.0f); glVertex2f(2.0f,1.0f); //C
glTexCoord2f(0.0f,1.0f); glVertex2f(0.0f,1.0f); //D
glEnd();This will -- assuming no anti-aliasing -- produce two fragments, like this:
| | |
| # | # |
| | |
A-----+-----BOpenGL treats pixels just like texels: small rectangles (with an area, unlike points), where the edges lie on whole number coordinates (in window space). Interpolated attributes, including texture coordinates, and all fragment processing are evaluated at the centers, not at the edges.
In this example, the left fragment has the texture coord (0.25f;0.5f) and the right fragment has the texture coord (0.75f;0.5f). This exactly hits texel centers, so the texture won't be distorted.
Now. You use a constant r texture coordinate, so that one won't be fixed up by interpolation. That's all. OpenGL does not treat the r texcoord any different from the s and t texcoords.
Hope this was understandable. After reading through my post I find it mildly confusing, but I can't do better right now :)
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.