Advertisement Jump to content
Sign in to follow this  

help getting texture coordinates after transformation

This topic is 4887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I would like to know if is it possible before give texture coordinates to the rasterizer (before pixel shader), transformate them inside the vertex shader ?? For example, if I have defined four vertex with this texture coordinates vertex 1 (u,v) = (0, 0) vertex 2 (u,v) = (1, 0) vertex 3 (u,v) = (0, 1) vertex 4 (u,v) = (1, 1) Can I make a translation of 0.055 for example in x axe? image x dimension = 100 So a translation of 5.5 pixels ?? (5.5/100=0.055) vertex 1 (u,v) = (0.055, 0) vertex 2 (u,v) = (1.055, 0) vertex 3 (u,v) = (0.055, 1) vertex 4 (u,v) = (1.055 .1) So when I get texture coordinates...and multypliing for the image size .. ! Watch that pixels in (3,0) it's now (3+5.5,0) = (8.5 , 0) and so get the floor of this x coordinate (8) and the frac (0.5) ??? What will happen with 1.055 since texture coordinates must be in the range [0,1] ?? And's the interpolator of the rasterizer, going to make a good interpolation for each pixel, if in case of a simple translation I make a rotation?? This is exatly what I'm looking for but I don't know if it is possible. Anny suggestion ?? Thanks again! Jesus

Share this post

Link to post
Share on other sites
The OpenGL advice holds true here in the DX forum. :)

// Wrap in both U and V.

// Clamp both U and V between 0 and 1.

This holds true if using a shader or not.

In a vertex shader you're free to apply whatever transform to your coordinates you want. You can also transform texture coordinates in the fixed pipeline.

// Enable transform of UV
pDev->SetTransform(D3DTS_TEXTURE0, &matrix);

Where matrix isn't quite a standard 4x4 matrix, though you do pass in a regular matrix. You can use rotation around Z, or scale of X, and Y. Translation goes in a different place, mat._31, and mat._32 instead of mat._41, mat._42, mat._43.

Remember to disable the transform flags (D3DTTFF_DISABLE) before drawing more items that don't want transformed coordinates.

Share this post

Link to post
Share on other sites
Original post by rip-off
Original post by yurixd

What will happen with 1.055 since texture coordinates must be in the range [0,1] ??

they dont have to be. it depends on your gl setup.


where VALUE is:

GL_CLAMP ( texture just stops a 1.0 )

GL_REPEAT ( texture repeats itself every 1.0 )

i've never done vertex shaders but i assume this holds true

If you want to do this in D3D, just use IDirect3DDevice9::SetSamplerState():


Share this post

Link to post
Share on other sites
Thanks for the answers....but I don't know what does clamp and wrap do. I think clamp will erase all pixels with texture coordinates bigger than 1??? And wrap will give for a pixel textures value (1.2,1.6) --> (0.2,0.6)?? Is that true?

I want to know..if I can give to the pixel shader values for coordinates textures bigger than 1.
For example. If I defined a quad ... the upper-left corner have
(u,v) = (0.3, 0)
and for the upper right corner
(u,v) = (1.3, 0 )

And if the image is of dimension 10 on the size x...
will the interpolator give me the next values ??

(0.4, 0)
(0.5, 0)
(0.6, 0)
(0.7, 0)
(0.8, 0)
(0.9, 0)
(1.0, 0)
(1.1, 0)
(1.2, 0)

This is just what I,m looking for!!!

Thanks for all your suggestions!!

Share this post

Link to post
Share on other sites
The interpolater will indeed give the numbers you listed (... 0.9, 1.0, 1.1, ...). However, in PS.1.1, if you attempt to use these numbers as colors rather than texture coordinates, they become clamped between 0 and 1. In later shader models you will see numbers outside the 0..1 range.

The texture addressing modes control how to perform texture lookup with UVs outside the 0..1 range.

Clamp means anything less than 0 is 0, and anything greater than 1 is 1. This will repeat the edge texel.

Wrap means the texture wraps around to the opposite side every 1.0. If you have a brick pattern that you want repeated 10 times across a polygon, you just use UVs of (0,0) to (10, 10). You don't need to make new geometry to keep the UVs within 0..1.

Mirror means the texture acts as though 0=0, 1=1, 2=0, 3=1, etc. For example going from 0.0 to 2.4 may do this:
0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 0.8, 0.6, 0.4, 0.2, 0.0, 0.2, 0.4.

Border seems to be supported only on nVidia. UVs outside the 0..1 range become the border color, which is D3DCOLOR you can specify.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!