11

Just installed the iOS 9 open beta (version 3) and now I'm having loads of problems with SpriteKit shaders. On iOS 8 the following code worked just fine:

_fontShader = [SKShader shaderWithFileNamed:@"TheShader"]; // TODO: iOS9 compatibility issues here
_fontUniform = [SKUniform uniformWithName:@"labelBase" float:0];
[self.fontShader addUniform:self.fontUniform]; // TODO: iOS9 compatibility issues here

_fontEffects = [SKEffectNode node];
self.fontEffects.shader = self.fontShader; // TODO: iOS9 compatibility issues here
self.fontEffects.shouldEnableEffects = YES;
self.fontEffects.shouldCenterFilter = NO;
self.fontEffects.shouldRasterize = YES;
[self addChild:self.fontEffects];

Edit: the file "TheShader.fsh" looks like this:

float yPos = gl_FragCoord.y - labelBase; // iOS 9 Compatibility issues here
float gradient = 0.35*(yPos / u_sprite_size.y); // ranges from 0 at base to 0.35 at top

vec4 color = SKDefaultShading(); // the current label color (iOS 9 Compatibility issues here)
color = vec4(gradient + color.r, gradient + color.g, gradient + color.b, color.a);
color.rgb *= color.a; // set background to alpha 0

gl_FragColor = color;

On iOS 9 the console is spewing out a pile of warnings in this format:

2015-07-12 22:43:17.717 ReconInForce[599:110531] Jet: Error Domain=MTLLibraryErrorDomain Code=3 "Compilation failed: 

program_source:8:18: error: use of undeclared identifier 'gl_FragCoord'
    float yPos = gl_FragCoord.y - labelBase[0];
                 ^
program_source:11:18: error: use of undeclared identifier 'SKDefaultShading'
    vec4 color = SKDefaultShading(); // the current label color
             ^
" UserInfo=0x158c084b0 {NSLocalizedDescription=Compilation failed: 

program_source:8:18: error: use of undeclared identifier 'gl_FragCoord'
    float yPos = gl_FragCoord.y - labelBase[0];
             ^
program_source:11:18: error: use of undeclared identifier 'SKDefaultShading'
    vec4 color = SKDefaultShading(); // the current label color
             ^
}

Seems like iOS9 is not supporting SKDefaultShading and gl_FragCoord. How do I find the local pixel dimension without using gl_FragCoord?

The console continues to repeat this forever, slowing down the device. Here's a screenshot: enter image description here

If I comment out the lines above that say "iOS9 compatibility issues here" then the problem resolves itself, but then I don't have any shaders.

Anyone else having this issue? Much help would be appreciated.

8
  • This is more than likely a bug on their side. I was updating some stuff today and ran into these problems as well.
    – Tony
    Aug 25, 2015 at 17:10
  • Did figure this out? Running into the same issue on Xcode 7.0 and iOS 9.1 public beta 1. Sep 19, 2015 at 15:43
  • Not yet, file a bug report if you can. The more reports the faster they might fix it! Sep 19, 2015 at 15:46
  • When will Apple pay attention to SpriteKit, my games are all broken in iOS9, im receiving bad reviews, and its not my fault. This is terrible. Anyone have a radar number yet?
    – txaidw
    Sep 30, 2015 at 11:45
  • The SDK documentation doesn't mention anything about SKDefaultShading being deprecated or anything. I filed a bug and gave feedback on the doc page as well, see if they update it, developer.apple.com/library/prerelease/ios/documentation/…
    – endavid
    Oct 26, 2015 at 9:14

4 Answers 4

6

I came here after seeing the message use of undeclared identifier 'gl_FragCoord' but eventually I could solve my problem by replacing

gl_FragCoord.xy / u_sprite_size.xy

with

v_tex_coord

1
  • Ok this helped me with a similar problem. Seemed gl_FragCoord was bad too.
    – Jonny
    Jan 15, 2016 at 8:20
2

My custom SKShader also stopped working in ios9 on metal devices.

I was able to fix it using v_tex_coord to get the pixel position, and custom uniform to send in the sprite size (There seems to be a bug where u_sprite_size isn't being passed in.)

[SKUniform uniformWithName:@"u_fixed_size" floatVector2:GLKVector2Make(n.calculateAccumulatedFrame.size.width, n.calculateAccumulatedFrame.size.height)]
3
  • Can you please add more information and code, how to substitute / calculate gl_FragCoord based on what you mentioned in your accepted answer. Many Thanks!
    – nzs
    Oct 5, 2015 at 9:33
  • This does not solve the issues for me. SKDefaultShading() seems to be gone.
    – Jonny
    Jan 15, 2016 at 3:58
  • BTW I think u_sprite_size is deprecated.
    – Jonny
    Jan 31, 2017 at 8:44
2

Try to add parameter 'PrefersOpenGL' of type boolean set to 'YES' in info.plist. This will disable Metal

1

I had this problem too with iOS9. gl_FragCoord stopped working on real devices, but works in the iOS simulator.

Work around.

Create a node with shader

let shader = SKShader(fileNamed: "polka.fsh")
let uniform = SKUniform(name: "u_spriteSize", floatVector2: GLKVector2Make(Float(200), Float(200)))
shader.uniforms.append(uniform)

Update the uniform

if let uniform = shader.uniformNamed("u_spriteSize") {
    let size = frame.size
    uniform.floatVector2Value = GLKVector2Make(Float(size.width * screenScale), Float(size.height * screenScale))
}

Shader

vec2 xy = v_tex_coord * u_spriteSize - u_polkaCenter; // new code
//vec2 xy = gl_FragCoord.xy - u_polkaCenter;  // old code that worked before iOS9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.