Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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; 

do

Output.TextureUV = mul( vTexCoord0, texTrans );

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

share|improve this question
    
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 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 at 10:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.