在 SceneKit 中使用着色器修改器对纹理进行动画处理会导致纹理随着时间的推移而抖动 [英] Using shader modifiers to animate texture in SceneKit leads to jittery textures over time

查看:23
本文介绍了在 SceneKit 中使用着色器修改器对纹理进行动画处理会导致纹理随着时间的推移而抖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 SceneKit for iOS 编写一个场景.

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);" };

一切都很好.除了随着时间的推移,纹理开始出现随机抖动,尤其是沿 x 轴.

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.

另外:我不确定如何从着色器代码中记录数据.能够查看诸如u_time"之类的变量并确切了解发生了什么会很棒.

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.

推荐答案

肯定是浮点精度问题.您可能应该尝试对 (u_time*30.0) 进行取模,使其在合理范围内循环.

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.

这篇关于在 SceneKit 中使用着色器修改器对纹理进行动画处理会导致纹理随着时间的推移而抖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆