Using shader modifiers to animate texture in SceneKit leads to jittery textures over time

后端 未结 2 1833
温柔的废话
温柔的废话 2020-12-11 11:03

I\'m writing a scene in SceneKit for iOS.

I\'m trying to apply a texture to an object using a sprite sheet. I iterate through the images in that sheet with this code

相关标签:
2条回答
  • 2020-12-11 11:28

    It's definitely a floating point precision issue. you should probably try to do a modulo on (u_time*30.0) so that it loops within a reasonable range.

    0 讨论(0)
  • 2020-12-11 11:37

    if you want to iterate over images your texture coordinate must stay the same for a short period of time (1 second for instance).

    u_time is similar to CACurrentMediaTime(), it's a time in seconds.

    Now let's say you have N textures. Then mod(u_time, N) will increase every second from 0 to N-1 and then go back to 0. If you divide this by N you've got your texture coordinate, and you don't need SCNWrapModeRepeat.

    If you want your image to change every 0.04 second (25 times per second), then use mod(25 * u_time, N) / N.

    0 讨论(0)
提交回复
热议问题