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

查看:517
本文介绍了使用着色器修改器在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天全站免登陆