Here's the translated message with a working UV sprite atlas shader. Just for you and those interested coming from search engines.
Swyter said:mark7 said:Swyter said:You may want to do it your way by using your own shaders. Here are two ways I can think of right now:
1. Use every available texture slots in the material, so you'd be limited by the existing 6 slots.
The good thing is that you already have the code above, the one I wrote in my other post. It's about alternating between samplers, that in the pixel shader aren't more than numeric values from 0 to 5.
2. Paste all the frames into a single texture, vertically, like in a film strip, and just add a displacement in the pixel shader usingas modulator. It may take a while to thought it out, but the freedom that this method gives you is inmense.Code:time_var
The second method looks easier to me, and as you've said before, more feasible. Many games make use of that way of animating textures (that I know of). In fact I made my dynamic main menu just like that, with a displacement of the texture by the X axis.
So to get a working texture animation should I do something like this?
float speed = 1.05; // displacement speed
tc.x -= speed*time_var;
Thanks in advance.
/Mark7
In this example I'm using the vertical axis, but it doesn't really matter, just be cautious when changing coordinates...
Code:[color=navy]/* sawtooth staircase pixel shader -- created by swyter */ /* online GLSL live proof-of-concept here: http://glsl.heroku.com/e#11374.0 */ // 0.f // _ A // |_| | // |_| | // |_| | // |_| | // |_| | Y // |_| | // |_| | // |_| | // V // 0.f <-> 1.f // X Vertex shader: --------------[/color] int frame_count = 8; [color=navy]// total number of animation frames[/color] int frame_height = 64; [color=navy]// per-frame vertical pixels, fixed[/color] int total_height = frame_count * frame_height; [color=navy]// vertical pixels of the whole image[/color] float sawtooth = time_var - floor(time_var); [color=navy]// goes from zero to one and starts again, it subtracts itself (57.3 - 57 = .3)[/color] uv.y /= frame_count; [color=navy]// scale the coordinates reducing them to show just the first frame (1/8)[/color] uv.y += floor(sawtooth * frame_count) [color=navy]// expand the count from 0.0-1.0 to the total number of frames 0.0-8.0, while getting rid of the decimals, leaving an integer value like 3.7 -> 3.0[/color] uv.y /= frame_count [color=navy]// scale it back normalizing it to the 0-1 range, but now it will be jumping in discrete steps without transitions or sliding[/color] [color=navy]Pixel shader: -------------[/color] tex2d(diffuse, uv); [color=navy]// do the sampling in the correct coordinate, as always, there's no need of changing anything at all[/color]
I've created a tiny workbench so you can play around directly with the parameters in your browser, beware, this is GLSL, there are some variations respect to HLSL. It's done with colors instead of UV coordinates, and plays a frame per second, should be helpful:
Code:http://glsl.heroku.com/e#11374.0