如何在场景套件中创建动画纹理? "fallback on default program"错误


我想在 SceneKit 中使用动画纹理,

我发现这个 使用着色器修饰符在 SceneKit 中对纹理进行动画处理会导致随着时间的推移抖动纹理,但我在相同的代码中遇到错误:

C3DResourceManagerMakeProgramResident 无法编译程序 - 默认程序的回退

我尝试使用另一个文件作为着色器(>空>称为animated.shader的新文件(,并改用此代码,但是我遇到了相同的错误:

let fireImage = UIImage(contentsOfFile: "art.scnassets/torch.png")
myMaterial = SCNMaterial()
myMaterial.diffuse.contents = fireImage
myMaterial.diffuse.wrapS = SCNWrapMode.Repeat
myMaterial.diffuse.wrapT = SCNWrapMode.Repeat
myMaterial.shaderModifiers = [ SCNShaderModifierEntryPointGeometry : "uniform float u_time; _geometry.texcoords[0] = vec2((_geometry.texcoords[0].x+floor(u_time*30.0))/24.0, (_geometry.texcoords[0].y+floor(u_time*30.0/24.0))/1.0);" ]
plane.materials = [myMaterial]
//OR :
let url = NSBundle.mainBundle().pathForResource("animated", ofType: "shader")
let str = String(contentsOfFile: url!, encoding: NSUTF8StringEncoding , error: nil)
let nstr = NSString(string: str!)
myMaterial.shaderModifiers = [ SCNShaderModifierEntryPointFragment: nstr ]
plane.materials = [myMaterial]

我尝试使用一个简单的着色器,可以肯定的是,它在文档中提供了Apple,并且它有效。所以问题来自我正在使用的代码。

在这里找到了第二个代码(wiki unity(:link,我稍微更改了一下以使用glsl而不是unityscript

uniform float u_time;
float numTileX = 24;
float numTileY = 1;
float fps = 30;
float indexA = u_time * fps;
float index = index % (numTileX * numTileY);
float uIndex = index % numTileX;
float vIndex = index / numTileY;
_geometry.texcoords[0] = vec2( (_geometry.texcoords[0].x + uIndex) , (_geometry.texcoords[0].y + vIndex) );

编辑:这是错误:

错误 :

SceneKit: error, failed to link program: ERROR: 0:66: '%' does not operate on 'int' and 'int'
ERROR: 0:67: Use of undeclared identifier 'index'
ERROR: 0:68: Use of undeclared identifier 'index'
ERROR: 0:69: Use of undeclared identifier '_geometry'

新代码 :

int numTileX = 24;
int numTileY = 1;
float fps = 30.0;
float indexA = u_time * fps;
int indexI = int(indexA);
int total = int(numTileX * numTileY);
int index = indexI % total;
float uIndex = index % numTileX;
float vIndex = index / numTileY;
_geometry.texcoords[0] = vec2( (_geometry.texcoords[0].x + uIndex) , (_geometry.texcoords[0].y + vIndex) );

你知道怎么解决这个问题吗?

谢谢

如果不了解有关着色器编译错误的更多信息,则很难判断该着色器代码是否有更多问题,但是您收到的错误意味着着色器程序无法编译。

仅通过查看着色器代码,我想我看到了两个错误:

  1. 场景工具包已声明当前时间的统一float u_time;(以秒为单位(,该在所有入口点都可用。此外,u_a_v_前缀由场景工具包保留,不应用于着色器修改器中的自定义变量。

  2. GLSL 对类型转换非常挑剔。将整数类型分配给浮点变量不会导致强制转换(就像在 C 中那样(,而是类型错误。

这意味着,例如:

float numTileX = 24;

是类型错误,应重新定义为:

float numTileX = 24.0;

同样的事情也适用于混合整数和浮点类型的算术。

最新更新