Author Topic: Moving texture  (Read 1639 times)

Offline keaukraine

  • byte
  • *
  • Posts: 34
    • View Profile
Moving texture
« on: December 02, 2010, 02:03:09 pm »
Hi,

How can I change texture UV coordinates to move it in some loop?
I want to achieve effects like falling rain drops (place some transparent polygons with rain texture and continuously move texture in the bottom direction to achieve desired effect), or grass waving on the wind (move texture in the left/right direction), water running in the river, etc...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Moving texture
« Reply #1 on: December 02, 2010, 02:42:53 pm »
You have different options for this:

  • Don't! Move the geometry instead if possible.
  • Change the uv-coordinates at runtime. You can do this by using the PolygonManager. You have to call Object3D.compile(true, false); on the objects in question and you must not call strip on them.
  • Modify the texture matrix of the object (Object3D.setTextureMatrix()). This is actually the best way, if there wouldn't be one large drawback: It doesn't work! At least not in some Qualcomm drivers, which simply don't handle the texture matrix stack correctly on Android.

Offline keaukraine

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Moving texture
« Reply #2 on: December 02, 2010, 03:21:59 pm »
OK, so the only way to do it is using PolygonManager.
The next question is: how expensive is calling Object3D.compile(true, false) on each frame redraw? I will need to animate moving textures for objects like water, clouds, etc...
Can I call only touch() as stated here: http://www.jpct.net/forum2/index.php/topic,1689.0.html , or it's no enough to update UVs?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Moving texture
« Reply #3 on: December 02, 2010, 03:59:11 pm »
Just update the uv's and call touch(). There's no point in calling compile(...) for each frame. It would be a nop anyway. Regarding performance, rendering static objects is faster than rendering dynamic ones (at least if they actually change...if they don't, it doesn't matter) and changing uv is even more expensive. As long as the objects are pretty simple, it shouldn't matter that much though. Just make sure to reuse TextureInfo-instances instead of creating new ones and call touch() only if something has changed.
As said, if you can move the geometry instead, then do it. Clouds, for example, can easily be animated by rotating a sky dome/box instead of modifying uv coordinates.