Good way for texture animations
Hi,
I've been thinking about texture animations recently and wonder about a good way to do it.
I often see square textures with the individual frames put into different rows and columns. But why does the texture have to be square? Wouldn't it be much easier to just place one frame after another. Than you would only have to multiply the texture coordinates by the frame number in the shader and all would be done. Instead of finding the correct row ect.
Is it in-efficient to have a very "wide" texture instead of a square one.
What about texture-arrays? I guess it would be slightly inconvenient to prepare the textures, but are they slower on the graphics card?
you have still some limitations for texture resolutions, 2048, 4096 and 8192 are common.
additionally there is some precission limit for "half" mapped to int coordinates, you're safe if you stay with +-1024 afaik.
additionally there is some precission limit for "half" mapped to int coordinates, you're safe if you stay with +-1024 afaik.
There are also limitations on aspect ratios of textures on some cards they just don't work if you asked for ratios outside 1:8 - 8:1
Personally what I have done is built a small app that will take a folder of textures and generate a square sprite sheet. The app also generates an XML file that list every frame's position in a Rectangle format (x, y, w, h). The animation class then just passes the uv coordinates (rectangles) to the render along with the sprite sheet to do rendering. I built it that way so if an artist wants to specify their own coordinates, or use a pre-existing non-square sprite sheet, they could.
A big part of what I would need this for is the particle renderer. I don't really want to send texture-coordinates with every particle, so I guess I have two options:
1.) I calculate the texture coordinates in the vertex shader based on the rows and columns of the sprite sheet.
2.) I calculate all possible coordinates on the cpu and send an array to the shader which I just index.
Not sure which I prefer, but 2.) sounds good to me especially if a lot of particles can reuse that array.
1.) I calculate the texture coordinates in the vertex shader based on the rows and columns of the sprite sheet.
2.) I calculate all possible coordinates on the cpu and send an array to the shader which I just index.
Not sure which I prefer, but 2.) sounds good to me especially if a lot of particles can reuse that array.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement