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

kri*_*nan 5 ios scenekit swift metal

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

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

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

let material = SCNMaterial()
material.program = program
material.setValue(metalTexture, forKey: "customTexture")
Run Code Online (Sandbox Code Playgroud)

问题与此问题完全相同.将 Metal texture2d_array传递给SceneKit着色器修改器

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

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

Ree*_*eng 3

将金属纹理包裹在SCNMaterialProperty物体中会起作用。

let imageProperty = SCNMaterialProperty(contents: metalTexture)
material.setValue(imageProperty, forKey: "customTexture")
Run Code Online (Sandbox Code Playgroud)