SKShader on 10.11 (Metal vs OpenGL ES)

I am creating a game in Swift + SpriteKit that makes heavy use of shaders.


All the documentation I can find still states that SKShader(fileNamed: "myshader.fsh") requires that the source file be written in the OpenGLES shader language. This used to be the case but on 10.11 and XCode 7 my shaders throw runtime errors because they seem to be being compiled with the metal shader compiler.


I was under the impression that even though SpriteKit now uses metal under the hood, existing shaders would continue to work. Is that not the case?

Accepted Reply

Most SKShaders shaders are fully supported in both OpenGL & Metal. If you run into cases that are not, please file a bug report with your specific shader source.



By default, SpriteKit and SceneKit render with Metal in iOS 9 and OS X El Capitan, however, there is a facility to use OpenGL.


IMPORTANT: For optimal performance, Metal rendering in SpriteKit and SceneKit is enabled by default. Setting PrefersOpenGL rendering key is not recommended unless it is determined necessary for other reasons.


To do that:

  1. Edit your app's Info.plist
  2. Add the
    PrefersOpenGL
    key with a bool value of YES

Replies

Most SKShaders shaders are fully supported in both OpenGL & Metal. If you run into cases that are not, please file a bug report with your specific shader source.



By default, SpriteKit and SceneKit render with Metal in iOS 9 and OS X El Capitan, however, there is a facility to use OpenGL.


IMPORTANT: For optimal performance, Metal rendering in SpriteKit and SceneKit is enabled by default. Setting PrefersOpenGL rendering key is not recommended unless it is determined necessary for other reasons.


To do that:

  1. Edit your app's Info.plist
  2. Add the
    PrefersOpenGL
    key with a bool value of YES

Hi toriol,


Thanks for posting that.


Using that setting, all my SKEffectNode and SKEmitterNode problems dissappear - I have an app that I can release now.


Is there a timeline or expected release for resolving the problems we are seeing with Metal?

As a small elaboration, as of the writing of this post, SKShaders support the OpenGL ES 2.0 shading language. So the comment: "Most SKShaders shaders are fully supported in both OpenGL & Metal" refers to SKShader honoring a GLSL shader regardless of SpriteKit's active renderer, be it GL or Metal. See QA1904 - Specifying the renderer for SpriteKit and SceneKit https://developer.apple.com/library/content/qa/qa1904/_index.html