[SOLVED] Creating animated pictures class for 2d Hud

Seens good, how to I do it ? Witch class ? Texture is the one ?

Step 1: learn shader coding
Step 2: fork unshaded
Step 3: add the lines of code to move the texture coordinates

The tricky part for us helping is that we don’t really know the requirements. Is this the only effect you want? How do you plan to send the effect parameters to the shader? Etc.

Where as if you got through step (1) above then you could answer most of those questions easily and we could give you advice.

2 Likes

No, you do nothing to Texture at all. Texture is just an image and should remain just an image.

Do edit fragment shaders you do shader editing… part of material definition.

Thus my recommended step (1) in my other reply.

Thanks @pspeed , I will look at it.
I found some info about an class called Effect , should I look on it ?

Have you tried looking at the matDefs for particles?

isnt this what you are looking for?

I have no idea what Effect is or where you’ve found it. Doesn’t seem to be a JME class.

Either way, I very much doubt it has anything to do with JME shaders since JME default shaders don’t have anything like what you are trying to do.

I thought that was just a sprite sheet… or does it include texture coordinate-based animation also?

Yes, its an Jm3 class, its in the wiki : http://wiki.jmonkeyengine.org/doku.php/jme3:contributions:tonegodgui:createeffects

No, it’s a tonegodgui class… it’s right in the URL.

I thought it was Jm3 core, since I can instantiate directly : import de.lessvoid.nifty.effects.Effect;

Ops, forget about, it seens its not the same class :blush:

And that one is in nifty, not JME. FYI.

I dont know if I am reading this vert wrong but it looks like it is doing the animation.

niform mat4 g_WorldViewProjectionMatrix;
uniform float m_SizeX;
uniform float m_SizeY;
uniform float m_Position;
 
attribute vec3 inPosition;
attribute vec2 inTexCoord;
 
varying vec2 texCoord;
 
void main(){
 
    float t = m_Position;
    float tPointerY = 1.0 - ((floor(m_Position / m_SizeX)) / m_SizeY) - 1.0 / m_SizeY;
    float tPointerYOffset = (floor(t / m_SizeX)) / m_SizeY;
    float tPointerX = (t - (tPointerYOffset * m_SizeX * m_SizeY)) / m_SizeX;
    texCoord.x = inTexCoord.x / m_SizeX + tPointerX;
    texCoord.y = inTexCoord.y / m_SizeY + tPointerY;
    gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
}

Those are very good info @skidrunner !
I will take a look on that, and seems I will learn a lot about it as well :slight_smile:

Where do you see animation in there?

…just normal texture atlasing to me.

your right :frowning: but wouldnt you be able to move the sprites yourself in code using a control for the animation on the sprite isnt that the point of using sprites for animation?

position = position > maxPosition ? 1 : position + speed * tpf;
mat.setFloat("Position", (int) position);

or somethign like that?

I made some modifications, its working, but I am wonder, do I need to create one vert file for each animation ? What if I want to determine the direction from the animation by run-time ?

Obs: I tried the animation from down to up :

float t = m_Position;

float tPointerYOffset = (floor(t / m_SizeX)) / m_SizeY;

float tPointerY = (t - (tPointerYOffset * m_SizeX * m_SizeY)) / m_SizeX;
float tPointerX = 1.0 - ((floor(m_Position / m_SizeX)) / m_SizeY) - 1.0 / m_SizeY;

tPointerY=tPointerY*-1;

texCoord.x = inTexCoord.x / m_SizeX + tPointerX;
texCoord.y = inTexCoord.y / m_SizeY + tPointerY;
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

In other words, its possible to generate this material at run time ?

Yes, if you want cell animation that works but if you just want to slide texture coordinates then that won’t work on its own. You have to modify the texture coordinates somehow… but now I get dangerously close to repeating myself. :wink:

You don’t really want to generate a material at runtime. You want to make a better material.

Like instead of just moving it based on time move it based on a vector * time.

ie: write a shader that incorporates all of your desired features. Or instead do my original option (2) and ignore the shader and just modify texture coordinates in code instead and do whatever you want with them.