Search code examples
iosswiftsprite-kitglslmetal

SpriteKit shaders on iOS 16 - Y-axis is inverted


My SpriteKit app, which uses several GLSL fragment shaders, is showing different shader behaviour on iOS 16 as compared to iOS 15 and earlier. On iOS 15 the y-axis increased in the direction of the bottom of the screen, but now suddenly iOS 16 appears to have inverted this and now the y-axis is increasing in the direction of the top of the screen.

The fact that this change is occurring only in my fragment shaders while SpriteKit node positioning remains unchanged between iOS 15 and 16 leads me to believe that this might be a change made in Metal 3.

Is there an elegant solution to achieving consistent behaviour between iOS versions here? I would prefer not to have to detect the user's iOS version and supply a shader uniform to invert the y-axis manually, on a per-shader basis.


Solution

  • Update 9.15.2022

    Based on the comments, it looks like this is indeed a bug (95579020) and an Apple Engineer confirmed that a fix has been identified (https://developer.apple.com/forums/thread/713945).

    However, the SKShader issue doesn't seem to happen when building on an Apple silicon laptop with Xcode 14.0. Not sure about the CIFilter issue.

    Original

    Are you using v_tex_coord? I have tested this and it doesn't look like there's a problem between iOS 15 and iOS 16, using v_tex_coord. There must be something else.

    Note: I have tested this on the iOS 16.0 simulator, not on a real device.

    The documentation also still mentions the bottom-left corner:

    vec2 v_tex_coord; Varying The coordinates used to access the texture. These coordinates are normalized so that the point (0.0,0.0) is in the bottom-left corner of the texture.

    The results are the same on both iOS versions using the SKShader code below and v_tex_coord.y:

    void main() {
        vec3 red = vec3(1.0, 0.0, 0.0);
        vec3 blue = vec3(0.0, 0.0, 1.0);
        vec3 col = mix(red, blue, v_tex_coord.y);
        
        gl_FragColor = vec4(col, 1.0);
    }
    

    iOS 15.0 -> Yaxis_Shader             iOS 16.0 -> Yaxis_Shader