# Transform texture coordinates when using shader

Assuming I define four vertices of a quad with texture coordinates that cover a whole texture or region of a texture, I can animate these coordinates by setting a transform using

SetTransform( D3DTS_TEXTURE0, &texTrans )


...scaling, translating etc.

If I render using a shader, and still want to animate the coordinates, presumably I can pass in the same transformation matrix and multiply the coordinates in the vertex shader?

Output.TextureUV = vTexCoord0;


do

Output.TextureUV = mul( vTexCoord0, texTrans );


Is this a/the correct way to render an animated sprite with shader?

• I think it is at least I do it the same way. Do you have a problem with this? – János Turánszki Jun 19 '14 at 17:13
• @János Not really. Just wanted confirmation. I've just never seen an example of a HLSL shader that does this, not a lot of 2D stuff out there in general, really. I thought maybe that was because you could still use SetTransform in some way, but that seemed unlikely. Anyway, good to know this is correct. Thanks. – Scott Oliver Jun 20 '14 at 10:41

Output.TextureUV = mul( float4( vTexCoord0, 0.0f, 1.0f ), texTrans );