1

Is there any viable way to use textures with SCNProgram shaders in Scenekit? As far as I can tell there's no way to access the default SCNMaterial textures from within an SCNProgram (I know I can access them from shader modifiers, but unfortunately as far as I can tell there's no way I can do what I need to do with shader modifiers).

Managing my own textures is not easy, because the obvious place to bind them - in the material.handleBindingOfSymbol block - gets called once for every bit of geometry rendered with the material. In my case this is tens of thousands of times per frame, which seems crazy for something that only need be done once if the scene graph sorts the rendering state properly.

I had assumed that there would be a way to attach a texture to an SCNProgram or to the SCNMaterial so that the scengraph could manage the rendering state, but for the life of me I can't find anything like that.

Am I missing something, or are textures basically unusable with SCNprograms?

jportway
  • 917
  • 8
  • 17
  • What can't you do in a set of shader modifiers? – David Rönnqvist Dec 10 '14 at 09:10
  • Hi David, thanks for your response. I'm rendering glowing geometry - unlike normal "transparent" shading this needs to act like light and be additively blended (as per my previous question that you responded to). The only way I've found to force sceneKit to composite it properly is with a custom shader that just does a texture lookup and returns the colour with alpha=0. Modifiers seem to assume normal lighting and have a lighting phase, and I can't work out whether that can just be bypassed to simply return an "unlit" colour. – jportway Dec 10 '14 at 13:38
  • Also, as I mentioned in [my previous question](http://stackoverflow.com/questions/27319549/using-blending-functions-in-scenekit?noredirect=1#comment43102388_27319549) , I can't seem to get SceneKit to enable blending without setting the "opaque=false" property on an SCNProgram - no amount of fiddling with the "transparency" property seems to make any difference, weirdly. So I'm not sure how to force blending on without an SCNProgram. – jportway Dec 10 '14 at 13:43
  • I've now edited the answer to my [previous question](http://stackoverflow.com/questions/27319549/using-blending-functions-in-scenekit?noredirect=1#comment43102388_27319549) because I worked out a hack that *does* allow me to use shader modifiers for my particular case. I'd still like to know whether there's a way to get SceneKit to manage texture resources when you're using your own custom programs though. It doesn't seem as if it should be too complex, since it's already doing it for its own shader, so the apparent omission of any functionality to help with that stuff is a bit baffling to me. – jportway Dec 10 '14 at 22:34

1 Answers1

1

There is no way to access the material textures as soon as a custom SCNProgram is set. a SCNProgram completely replaces SceneKit's rendering to let you do raw OpenGL|ES. So you indeed have to create and bind the texture yourself using GL.

Toyos
  • 4,024
  • 15
  • 16
  • I understand that SCNPRogram completely replaces SceneKit's rendering - I don't understand why scene kit can't still manage texture resources, since that's almost impossible to do satisfactorily yourself (especially if you're doing things like rendering a scene into multiple contexts etc.). Ho hum. – jportway Dec 12 '14 at 13:21
  • This answer includes how to pass textures to your SCNProgram: https://stackoverflow.com/a/37738386/211098 – Morty Jun 21 '17 at 16:10