How to make UV animation effect?

Started by tao, April 04, 2014, 10:54:06 AM

Previous topic - Next topic

tao

Hi,

I have a plane, and how can I make UV animations? I didn't find a way to change the UV attribute of a vertex. Pls help~

Thanks

tao

I found TextureInfo can change the vertex UV of each triangle, but still no idea how to make a 'water flow' animation using UV animation. Someone says I need to use shaders. Is that the only way? To use shader I have to use OpenGL2.0?

EgonOlsen

TextureInfo is one way of doing it, but for a water animation, it might not be the best one. Using TextureInfo, you are going to change the coordinates on the client side. That means that after a change, the data has to be uploaded to the GPU again, which can be expensive in terms of performance. If you want to do this, you have to use a special build() call to allow for uv coordinate changes (build(true);). You also have to use touch() on the object after modifying the coordinates.
Shaders are another way to do it. It's very flexible, but you have to use OpenGL ES 2.0 and you have to write your own shaders.
The easiest way is to assign a texture matrix to the object (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setTextureMatrix(com.threed.jpct.Matrix)). You can translate the matrix just like a normal tranformation matrix and it will translate the texture coordinates in the same way. Just make sure that your translation values don't get too large after time, so it's a good idea to reset them when possible (like if your value is larger than 1, you set it to value-1 instead).

tao

Thanks Egon, it's very detail  :)

public void build(boolean staticUV), I should use build(false), right?

Also, let me catch your idea ... so the way is like,

1) plane.build(false) at the creation of the plane.

2) then in each frame update ...
   2.1) translate texture matrix and plane.setTextureMatrix(matrix)
   2.2) plane.touch()

Am I right?

EgonOlsen

No, not quite. If you are using a texture matrix, there's no need for a special build call or touch. Just set the matrix...that's all.

tao

Yes, Texture Matrix does the job, thanks!  ;D