Sub-Texture animation, ideas?

Started by
6 comments, last by SoaringTortoise 19 years, 10 months ago
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
Always prey on the weak, the timid and the stupid. Otherwise you'll just get your butt kicked
For a tortoise, this is extremely hard to do, but when you get it right... the expression on their faces ...
Advertisement
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?

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

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.
Always prey on the weak, the timid and the stupid. Otherwise you'll just get your butt kicked
For a tortoise, this is extremely hard to do, but when you get it right... the expression on their faces ...
Tried to use a texture-coordinate transformation matrix?

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.
Always prey on the weak, the timid and the stupid. Otherwise you'll just get your butt kicked
For a tortoise, this is extremely hard to do, but when you get it right... the expression on their faces ...
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
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
Hmmm, I wasn''t feeling quite ready to jump into the PS and VS chunk of work just yet, but I think you may be right.
Always prey on the weak, the timid and the stupid. Otherwise you'll just get your butt kicked
For a tortoise, this is extremely hard to do, but when you get it right... the expression on their faces ...
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.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials

This topic is closed to new replies.

Advertisement