简体   繁体   English

iOS 16 上的 SpriteKit 着色器 - Y 轴反转

[英]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.与 iOS 15 和更早版本相比,我的 SpriteKit 应用程序使用多个 GLSL 片段着色器,在 iOS 16 上显示不同的着色器行为。 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.在 iOS 15 上,y 轴在屏幕底部的方向上增加,但现在 iOS 16 突然出现反转,现在 y 轴在屏幕顶部的方向上增加。

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.事实上,这种变化只发生在我的片段着色器中,而 SpriteKit 节点位置在 iOS 15 和 16 之间保持不变,这让我相信这可能是 Metal 3 中的变化。

Is there an elegant solution to achieving consistent behaviour between iOS versions here?是否有一个优雅的解决方案来实现 iOS 版本之间的一致行为? 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.我宁愿不必检测用户的 iOS 版本并提供着色器统一以手动反转 y 轴,基于每个着色器。

Are you using v_tex_coord ?你在使用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 .我已经对此进行了测试,使用v_tex_coord在 iOS 15 和 iOS 16 之间似乎没有问题。 There must be something else.一定有别的东西。

Note: I have tested this on the iOS 16.0 simulator, not on a real device.注意:我在 iOS 16.0 模拟器上测试过这个,而不是在真实设备上。

The documentation also still mentions the bottom-left corner:文档还提到了左下角:

vec2 v_tex_coord; Varying vec2 v_tex_coord; Varying The coordinates used to access the texture. vec2 v_tex_coord; Varying用于访问纹理的坐标。 These coordinates are normalized so that the point (0.0,0.0) is in the bottom-left corner of the texture.这些坐标被归一化,使点 (0.0,0.0) 位于纹理的左下角。

The results are the same on both iOS versions using the SKShader code below and v_tex_coord.y :使用下面的 SKShader 代码和v_tex_coord.y的 iOS 版本的结果相同:

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 -> iOS 15.0 -> Yaxis_Shader iOS 16.0 -> iOS 16.0 -> Yaxis_Shader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM