Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass MTLTexture to SCNProgram with metal vertex and fragment shaders

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?

like image 415
krishnan Avatar asked Oct 19 '22 05:10

krishnan


1 Answers

Wrap the metal texture in a SCNMaterialProperty object would works.

let imageProperty = SCNMaterialProperty(contents: metalTexture)
material.setValue(imageProperty, forKey: "customTexture")
like image 171
Reeonce Zeng Avatar answered Nov 15 '22 04:11

Reeonce Zeng