使用金属顶点和片段着色器将MTLTexture传递给SCNProgram

时间:2016-07-11 17:04:03

标签: ios swift scenekit metal

我有一个图像数组,我必须根据顶点随机选择一个图像,用金属我可以实现这个MTLTexture2DArray。

但是我使用的是SceneKit和Custom SCNProgram,它的问题是我无法将MTLTexture传递给Metal片段函数。

如果我将图像设置为SCNMaterial它可以工作,如果我设置了金属纹理,它会抛出异常。

let material = SCNMaterial()
material.program = program
material.setValue(metalTexture, forKey: "customTexture")

问题与此问题完全相同 Passing Metal texture2d_array to SceneKit shader modifier

但它使用着色器修改器,这里我使用自定义着色器。

是否可以将metal的texture2d数组传递给自定义SCNProgram,还是有另一种方法将图像数组传递给SCNProgram中的着色器函数?

1 个答案:

答案 0 :(得分:2)

SCNMaterialProperty对象中的金属纹理包裹起来会起作用。

let imageProperty = SCNMaterialProperty(contents: metalTexture)
material.setValue(imageProperty, forKey: "customTexture")
相关问题