Search code examples
iosswiftsprite-kitfragment-shader

Why is a shader not applied on a SKScene?


As per the documentation, SKScene is a child of SKEffectNode and thus should conform and apply the shader property if not nil.

I've successfully added a shader to individual SKSprites (so I know my shader code is working) but if I apply that same shader to the Scene, nothing happens, no error, nothing.

I've tried initializing the shader at multiple places :

  • in the init of the SKscene
  • in the ControllerView that initializes the SKscene
  • in sceneDidLoad of the SKscene to no avail.

Is there anything that I'm missing ?

(I'm using adapted code from https://github.com/twostraws/ShaderKit)

A similar question was asked 6 years ago (Applying a custom SKShader to SKScene that pixelates the whole rendered scene in iOS 8 SpriteKit with Swift) but labels the quirk as a bug (Maybe it was just never corrected in the meantime ?)


Solution

  • You should always remember to set shouldEnableEffects to true.