如何在SceneKit中创建动画纹理? “默认程序的后备"错误 [英] How to create an animated texture in SceneKit? "fallback on default program" error

查看:42
本文介绍了如何在SceneKit中创建动画纹理? “默认程序的后备"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在SceneKit中使用动画纹理,我发现了这个

I would like to use an animated texture in SceneKit, I found this Using shader modifiers to animate texture in SceneKit leads to jittery textures over time , but I have got an error with the same code :

C3DResourceManagerMakeProgramResident无法编译程序-默认程序的后备

C3DResourceManagerMakeProgramResident failed to compile program - fallback on default program

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

I tried to use another file for the shader (New file > Empty > called animated.shader), and use this code instead, but I have got the same error :

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,并且可以使用.所以问题出在我正在使用的代码上.

I tried with a simple shader that gave Apple in the documentation, to be sure, and it works. So the problem comes from the code I am using.

我在这里找到了第二个代码(维基统一):链接,我做了一些更改,以使用glsl代替unityscript:

I found the second code here (wiki unity) : link, I changed it a little bit to use glsl instead of 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) );


以下是错误:


Here are the errors :

错误:

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

您知道如何解决吗?

谢谢

推荐答案

在不了解有关着色器编译错误的更多信息的情况下,很难确定该着色器代码是否还存在其他问题,但是您得到的错误意味着着色器程序无法编译.

Without knowing more about the shader compilation error it's hard to tell if something more is wrong with that shader code, but the error that you are getting means that the shader program fails to compile.

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

Just by looking at the shader code, I think I see two errors:

  1. Scene Kit已经以秒为单位声明了当前时间的统一float u_time;,可在所有入口点使用.此外,u_a_v_前缀由Scene Kit保留,并且不得用于着色器修改器中的自定义变量.

  1. Scene Kit already declares the uniform float u_time; for the current time in seconds, that is available at all entry points. Further, the u_, a_, and v_ prefixes are reserved by Scene Kit and should not be used for custom variables in shader modifiers.

GLSL对于类型转换非常挑剔.将整数类型分配给float变量 not 不会导致强制转换(就像在C语言中一样),但实际上是类型错误.

GLSL is very picky about type conversion. Assigning an integer type to a float variable does not lead to casting (as it would in C), but is instead a type error.

这意味着,例如:

float numTileX = 24;

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

Is a type error and should be redefined as:

float numTileX = 24.0;

同样的情况适用于混合整数和浮点类型的算术.

The same thing applies to arithmetic that mixes integer and floating types.

这篇关于如何在SceneKit中创建动画纹理? “默认程序的后备"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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