Possible to create animated and multiple times repetitive texture on a triangle?

Started by
8 comments, last by Yann L 16 years, 10 months ago
Is that even possible in any good ways? Like i could do it by creating tons of triangles and putting them together, or binding the new texture for each frame and just adjusting texture coordinates, but those ways just sucks. I know how to animate it, but i cant make it repetitive. Thats my problem, i cant use that texture coordinates thing to make the texture smaller, and make it repeat itself, because then it would show other frame of the bigger image which is used to store all frames of the texture. If someone knows thats not even possible, just let me know.
Advertisement
3D textures.
I dont understand what you mean by that, can you explain any better?
Let me see if I have this right...
You have a texture made up of many frames of animation which you cycle onto the triangle (presumably with a texture transform). You want to also tile that texture across the triangle.

That being the case you're going to have to either tessellate the triangle to tile it, or have a different texture for each frame of animation. Which is better depends on texture size and amount of tiling required.

I wouldn't bother with 3d textures, they're too limited for this type of thing.
Quote:Original post by Jerax
That being the case you're going to have to either tessellate the triangle to tile it, or have a different texture for each frame of animation. Which is better depends on texture size and amount of tiling required.

Both are pretty bad ways to handle this situation.

Quote:Original post by Jerax
I wouldn't bother with 3d textures, they're too limited for this type of thing.

How so ? In fact, 3D textures are near optimal for this type of thing. They're as good as you can get in terms of performance and memory consumption for non-streamed animations. Texture arrays can be an alternative, but they're only supported on DX10 hardware.

Quote:
I dont understand what you mean by that, can you explain any better?

Sure. A 3D texture can be seen as a set of 2D texture slices, arranged in the form of a volume. Essentially, the idea is to store your animation frames along the third dimension.

You use the s and t texture coordinates as usual, just as if you were mapping a standard 2D texture. That includes tiling. The third coordinate, r, is then used to select the animation frame. By cycling the r coordinate from 0 to 1, you play the animation.

Of course, this assumes your animation is small enough to fit into video memory. If it's not, eg. if you're playing a movie on that texture or similar, then streaming the texture data over PBOs is the only reasonable option.
Quote:Original post by Yann L
How so ? In fact, 3D textures are near optimal for this type of thing. They're as good as you can get in terms of performance and memory consumption for non-streamed animations. Texture arrays can be an alternative, but they're only supported on DX10 hardware.

Lack of useful support for mipmapping.
Lack of support for large textures (3d texture sizes tend to be a lot more restricted than 2d - nvidia cards can only do 512, older ATIs are limited to 256).
Lack of support on older hardware. 2d textures work on most anything you care about, 3d don't.
Performance is no better and potentially worse than swapping textures each frame - you have to rebind the texture every frame anyway after all.

If you can fit your requirements into the mould of 3d textures they're great, but as a universal solution they leave somewhat to be desired.
Quote:Original post by Jerax
Lack of useful support for mipmapping.

Correct, but this is not necessarily a problem, depending on the type of animations you have. Texture arrays solve this entirely.

Quote:Original post by Jerax
Lack of support for large textures (3d texture sizes tend to be a lot more restricted than 2d - nvidia cards can only do 512, older ATIs are limited to 256).

Irrelevant. If you have an animation with a frame size larger than 512*512, you'd better off streaming it anyway.

Quote:Original post by Jerax
Lack of support on older hardware. 2d textures work on most anything you care about, 3d don't.

Irrelevant, unless you want to develop for the GeForce2...

Quote:Original post by Jerax
Performance is no better and potentially worse than swapping textures each frame - you have to rebind the texture every frame anyway after all.

3D textures tend to be faster in practice, unless you access them randomly in three dimensions, which would incure a lot of cache misses. But for animations, this is a non-issue. A set of 2D textures are not guaranteed to be in VRAM at any given time, single frames can be removed by the memory manager. They need to be swapped in again later over PCIe. A 3D texture, however, is guaranteed to be entirely in VRAM. As usual, profile.

Furthermore, 3D texture give you smooth filtering between frames for free, which can be an advantage for certain types of animations (eg. the typical water/lava/etc style, which I assume Emark wants, since he talked about tiling them).
Thanks for explanation, it helped a lot!

I will try that 3d texturing, it sounds interesting.

But i will ask is there any other ways of doing it than these three?
1) 3d texture.
2) Binding new texture for each frame, and adjusting texture coordinates.
3) Cutting the triangle into as many triangles as how many times you want to repeat the texture.

And how well that 3d texturing is supported on video cards?

And what other way should i use instead of 3d texturing if its not supported on the system?
3d textures are supported on GF3 or newer cards from nvidia, and most any ATI card you'll find. Intel 915 and 945 adpaters also support 3d textures, older intels do not.
All ATI and intel cards and nvidia cards prior to the 6 series only support power of 2 3d textures however, which means if you have a non-power 2 number of frames you could incur some serious wastage.

BTW, why would you need to adjust texture co-ords if you bind a new texture each frame? You should have them all laid out the same so all you have to do is swap the texture and it animates.


Quote:Irrelevant, unless you want to develop for the GeForce2...

Or Intel. You know the company that sells more GFX cards than anyone else.

Quote:3D textures tend to be faster in practice, unless you access them randomly in three dimensions, which would incure a lot of cache misses. But for animations, this is a non-issue. A set of 2D textures are not guaranteed to be in VRAM at any given time, single frames can be removed by the memory manager. They need to be swapped in again later over PCIe. A 3D texture, however, is guaranteed to be entirely in VRAM. As usual, profile.

You can ensure the textures stay in RAM by not using managed resources if that's an issue. If you're using enough video memory to cause swaps you're going to have issues either way since forcing the 3d texture in will cause the memory manager to swap other textures out. Either way you take the hit of the swap.
Quote:
But i will ask is there any other ways of doing it than these three?
1) 3d texture.
2) Binding new texture for each frame, and adjusting texture coordinates.
3) Cutting the triangle into as many triangles as how many times you want to repeat the texture.

4) Texture arrays (only on DX10 hardware)
5) Per frame streaming over PBO (only very large animations)

Quote:Original post by Jerax
Or Intel. You know the company that sells more GFX cards than anyone else.

If you target old Intel chipsets, and use OpenGL, then you have other things to worry about than 3D texture support... It ultimately depends on what Emarks target audience is, but chances are he isn't a commercial studio, and has the luxury of not caring about completely obsolete and bugged chipsets. Of course, you could still add multiple code paths, if you really need to (and that doesn't pertain only to animations - 3D textures are useful in so many ways).

Quote:Original post by Jerax
You can ensure the textures stay in RAM by not using managed resources if that's an issue.

You can't use non-managed resources in OpenGL.

Quote:Original post by Jerax
If you're using enough video memory to cause swaps you're going to have issues either way since forcing the 3d texture in will cause the memory manager to swap other textures out. Either way you take the hit of the swap.

I am constantly VRAM limited ;) Anyway, modern resource managers (especially under Vista) don't start swapping out when the memory is already full. They're swapping out and around (for memory defragmentation) pretty much constantly in the background. Many of them try to determine in advance (through past usage heuristics) what resources can go away. The problem with multiple textures as animation frames is the fact that the they look like the perfect prey for memory managers. Frame 0 hasn't been used for 199 frames - looks good, let's swap it out to make room for that request from Windows Vista for a compositing surface. Of course, the driver doesn't know that you only have 200 frames, and that frame 0 will be reused shortly. This doesn't occur with 3D textures or texture arrays.

Of course, it's highly probable that Emark isn't anywhere near being state change limited or VRAM limited. So he probably won't notice any performance difference at all between using 3D textures and single images. His call.

However, stay away from splitting the triangle to do the tiling. That's definitely not a good idea.

This topic is closed to new replies.

Advertisement