Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

SetTransform() for texture coordinates

Started by d000hg Mar 20, 2005 at 8:19 AM 6 replies 800+ views
Original Post
d000hg
d000hg
I'm using the fixed function pipeline with D3D 8.1. I use IDirect3DDevice::SetTransform() to set the projection, view and world matrices. I was under the impression that I can set a matrix to also transform texture coordinates. I want to be able to scale and translate the texture coordinates to save some work when I generate each frame - this would save wuite a bit of work. But when I tried setting the appropriate transforms nothing happened - no difference at all! Any clues...?
Aldenar
Aldenar
You need to set the texture transformation matrices as you did, but you also need to enable the texture transform using the D3DTSS_TEXTURETRANSFORMFLAGS texture stage state.
d000hg
d000hg
Thankyou. I have got it partially working now - I am able to set a scaling matrix but I'm not able to set a translation. Is this not supported for texture matrices? I tried manually setting D3DXMATRIX::_41 & D3DXMATRIX::_42 as well as creating a translation matrix with D3DXMatrixTranslation() but no luck. I set the texture stage state to use 2D texture coordinates since the textures are 2D - is there any change I can make to get what I want?
d000hg
d000hg
Anyone know about this? If I can only set a scaling matrix with no transform it's still of use to me but not nearly as much. I generate thousands of vertices each frame and scaling/multplying the texture coordinates is quite a performance hit. Plus in theory I could have both textures using only one set of texture coordinates with a different matrix, reducing the vertex size signigicantly...
Muhammad Haggag
Muhammad Haggag
Quote:
Original post by d000hg
Thankyou. I have got it partially working now - I am able to set a scaling matrix but I'm not able to set a translation. Is this not supported for texture matrices? I tried manually setting D3DXMATRIX::_41 & D3DXMATRIX::_42 as well as creating a translation matrix with D3DXMatrixTranslation() but no luck. I set the texture stage state to use 2D texture coordinates since the textures are 2D - is there any change I can make to get what I want?

Weird. Texture coordinate transforms work by applying the 4x4 matrix (here) , so translation should work. There's even a couple of examples in the documentation page linked above that do this.
- Are you sure the translation you applied would've changed the visual effect?
- Are the results the same on refrast?

d000hg
d000hg
Hmm, it looks like what I was doing but maybe not. Unless the matrix elements I would set for translations are different for 2D coordinates than 3D coordinates... that could be it. Sounds like it should work, will report back.
d000hg
d000hg
Yes that fixed it. Currently I set my texcoords like this when building vertices each frame (I store my data in 6byte-per-vertex format to save space but this must be expanded):
u0 = X * constant1
v0 = Y * constant1
u1 = X * constant1 + constant2
u2 = Y * constant1 + constant2

Now I can dispense with the 2nd texture coordinates entirely and use transforms to do it. On hardware T&L cards this will be a fair bit quicker I think; will D3D'x software version be faster or slower than what I was doing do you think? In either case I can shrink the vertex size by 8 bytes.

Thanks guys.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.