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

Josh Knowles

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:

happyMaterial = [SCNMaterial new];
happyMaterial.diffuse.contents = happyImage;
happyMaterial.diffuse.wrapS = SCNWrapModeRepeat;
happyMaterial.diffuse.wrapT = SCNWrapModeRepeat;
happyMaterial.shaderModifiers = @{ SCNShaderModifierEntryPointGeometry : @"_geometry.texcoords[0] = vec2((_geometry.texcoords[0].x+floor(u_time*30.0))/10.0, (_geometry.texcoords[0].y+floor(u_time*30.0/10.0))/7.0);" };

All is good. Except over time, the texture starts to get random jitteriness in it, especially along the x-axis.

Someone mentioned it could be because of "floating-point precision issues," but I'm not sure how to diagnose or fix this.

Also: I'm not sure how to log data from the shader code. Would be awesome to be able to look into variables like "u_time" and see exactly what's going on.

Toyos

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Texture gets over written when using multiple textures in GLSL shader

Scenekit: recolor diffuse texture with shader

SceneKit pass uniform vector to shader modifiers

Using a Metal shader in SceneKit

Repeating a texture over a plane in SceneKit

Swift: Obtain and save the updated SCNNode over time using projectPoint in scenekit

Rotate texture using vertex shader

iOS+SceneKit: How to apply toon shader on texture?

Using multiple textures for shader programming in Haskell

Slow texture fetch in fragment shader using Vulkan

Pass texture to GLSL shader without using uniform?

Referencing texels in a data texture using indexes in the shader

jQuery animate left over time

Performance advantage of using a TextureArray over an array of Textures?

OpenGL: Some clarification on using multiple textures or texture units

Texture units for preparing textures

Is it bad practice to reuse GL_TEXTURE0 over again when binding different textures?

Metal Shader with SceneKit SCNProgram

Using compute shader to return whether texture has certain colour

glsl using only vertex shader object loses color/texture

Proplem reading generated texture from fragment shader using ThreeJS

Scenekit - level of detail for materials/textures

SceneKit - Crossfade material property textures

Importing .obj files with textures in SceneKit

Using tar over ssh leads to gzip error in some cases

glm::rotate leads to bulging of texture

Compute Shader write to texture

Passing texture to shader in OpenGL

Rendering texture in OpenGL shader