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:
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.
Try to add parameter 'PrefersOpenGL' of type boolean set to 'YES' in info.plist. This will disable Metal
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.)
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
Update the uniform
Shader
I came here after seeing the message use of undeclared identifier 'gl_FragCoord' but eventually I could solve my problem by replacing
with