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?

Instead of in the vertex shader

Output.TextureUV = vTexCoord0; 


Output.TextureUV = mul( vTexCoord0, texTrans );

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

  • \$\begingroup\$ I think it is at least I do it the same way. Do you have a problem with this? \$\endgroup\$ Commented Jun 19, 2014 at 17:13
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Jun 20, 2014 at 10:41

1 Answer 1


I just stumbled back on this question, so I figure I should supply an answer. :)

The shader code I wrote in the question is almost right. I forgot that to convert a point with these transformations, the point needs to be in homogeneous coordinates.

See: https://stackoverflow.com/questions/5066532/how-to-multiple-a-2d-point-with-a-4d-matrix

So the correct vertex shader code would be:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .