5
votes

I have a array of images, i have to pick one image at the random based on the vertex, with metal i can achieve this MTLTexture2DArray.

But i am using SceneKit and Custom SCNProgram and the problem with it is i wasn't able to pass MTLTexture to the Metal fragment function.

If i set the image to SCNMaterial it works, if i set a metal texture it throws exception.

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

The problem is exactly the same as in this question Passing Metal texture2d_array to SceneKit shader modifier

but it uses shader modifier and here i am using custom shader.

Is it possible to pass metal's texture2d array to custom SCNProgram, or is there is another way to pass array of images to shader functions in SCNProgram?

1

1 Answers

3
votes

Wrap the metal texture in a SCNMaterialProperty object would works.

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