Archived

This topic is now archived and is closed to further replies.

SoaringTortoise

Sub-Texture animation, ideas?

Recommended Posts

Hi, If I have a big texture (2048x2048 pixels) and I want to scroll a part of that texture (a strip of 2048x128), what would be the most effective way of doing it in DX8? I need this scrolling to wrap that so as something shifts off the left edge it reappears on the right. Thanks

Share this post


Link to post
Share on other sites
Probably to use two seperate textures - one for the static part, and one for the animated part.

Either that, or get creative in your texture mapping. How are you displaying this texture - on a regular 3D model, or on a textured quad?

Share this post


Link to post
Share on other sites
I''m using it for my landscape (array of quads). The texture is basically seperated into tiles and the terrain uses a different UV to display a particular tile (mud, grass, etc). The idea here is to have a strip of tiles (2048x128) which contains 16 frames of animation going across. Updating the VB''s UV map for the landscape to scroll through the texture is slow, so I thought maybe I could scroll that strip of texture instead.

Share this post


Link to post
Share on other sites
Yah, but that seems to apply to either the whole VB or the whole texture.

To clarify a bit, what I''m doing is storing terrain patches (20x20 quads) into seperate VB''s and then using a simple frustrum cull to get rid of unseeable patches during the render. These VB''s are pre-defined during the map load so that all the render loop has to do is determine which quads are visible and shunt them to the pipeline. This is nice and quick and requires no run-time VB creation.

If I need to start batching the patches according to texture / texture transform, then the entire program needs to change. As it is, I set texture once, render the frustrum and I''m done.

What I''m proposing is to lock the texture and update a part of it during each loop (shift a 2048x128 row 128 pixels to the left, with wrap), which I think will be a lot faster than having to batch the terrain by texture.

Share this post


Link to post
Share on other sites
I haven''t thought this through, but it might help...

Can you do something in a shader if you store your coords + an ID of some sort. Do your texture transform in the shader based on time and only if some condition is met...???

Also, can you store your vertices in one stream, but have a separate (parallel) stream with animation flags/data/whatever? I''m thinking that you could update the relatively small amount of data in the second stream and then let the shader handle applying that data to the data in the first stream. (make sense?)

Like I said, I haven''t thought this through, but I bet the general approach of extra data + smarter VS or PS might get you pretty far.

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials

Share this post


Link to post
Share on other sites
It all depends on what exactly you''re doing, but...

Another approach might be to add one extra piece of data so that the vertex struct basically looks like

My XYZ position
My Normal
My Tex Coord
[one number that defines what I''m showing. Perhaps this is redundant with the tex coord....]

Now, assuming you have a relatively low number of possible animations, you could update a small number of VS constants with offset info for each animation. You could use the address register to apply the correct offset to the tex coords based on the identifier.

This assumes that you might have possible tiles like "waving grass", "bubbling lava", etc. If there are VS constants with offsets for each type, then you could have each type animate at different rates. The downside is that all lava will bubble the same, all grass will wave the same, etc. Unless... you could create each lava patch with different offsets into the animation strip. When you animate, they will all be the same speed, but out of phase.

Share this post


Link to post
Share on other sites