2

I'm trying to use a texture to modify a SCNPlane's vertex data. As per the documentation, and the WWDC 2013 slides, one simply needs to provide a SCNMaterialProperty using -setValue:forKey: on the plane or material. This works wonderfully, but only if the material property's -contents is set to either the string/URL to an image file, or the NSImage object itself. I get the appropriately deformed mesh (I'm setting the mesh's Z value to the R channel of the input texture).

I'm trying to use my own texture data though, which is generated initially from AVFoundation with some image processing done on the CPU. I've tried to provide it as an SKTexture, constructing a MDLTexture object (and all the various classes it requires), using GLKTextureLoader, and even brute-forcing the data into a GLKTextureInfo. Loading the image using NSImage, then extracting the NSBitmapImageRep and populating the various texture classes from this also doesn't work. Metal is not an option, since I don't own recent enough hardware everywhere this needs to work.

What's the best way to get texture data into a SceneKit shader modifiers? The fact that it works for images on disk suggests to me that I'm missing something, but I can't pinpoint what. class-dump doesn't suggest any immediately obvious methods I need to call either.

Many thanks!

sbwilson
  • 166
  • 9
  • Does http://stackoverflow.com/questions/18641434/using-existing-opengl-texture-with-scenekit?rq=1 help? – Hal Mueller Feb 20 '16 at 21:59
  • That covers the use of custom SCNProgram, rather than using Shader Modifiers. I suspect that there's some trick to using SCNMaterialProperty with anything other than the path to an image, though there's no clear documentation on what other preparation is required for texture loading. – sbwilson Feb 21 '16 at 04:41
  • After many more hours of playing, I've ditched this work and gone the custom SCNProgram route with, finally, much success. Curious to hear if there is an answer, because it'd be neat to be able to use the built-in lighting and other parts of SceneKit... – sbwilson Feb 29 '16 at 20:22
  • @sbwilson, did you notice that when you use custom SCNProgram you're loosing SceneKit's default frustum culling checks? Can you confirm or deny it? I'm having this trouble with Metal, but I believe frustum culling checks have nothing to do with rendering. – Ef Dot Mar 16 '16 at 15:37

0 Answers0