Hello there 👋
While running the following ViewController.swift
on iOS 16, I realized that the y
axis of v_tex_coord
inside the SKShader
has been inverted. The same code display a red bar at the top of the screen for iOS 15.5. This red bar is displayed at the bottom of the screen for iOS 16.
Here is some images to show you the difference:
iOS 15
iOS 16
Can you help me with this please?
Thanks a lot 🙏
import UIKit
import SpriteKit
class ViewController: UIViewController {
var skView: SKView?
var scene: SKScene?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
skView = SKView(frame: view.frame)
scene = SKScene(size: skView?.bounds.size ?? .zero)
scene?.backgroundColor = UIColor.red
view.addSubview(skView!)
skView!.presentScene(scene)
// Media
let mediaNode = SKSpriteNode(imageNamed: "archi1")
mediaNode.size = skView?.bounds.size ?? .zero
mediaNode.position = skView?.center ?? .zero
// Effect
let effectNode = SKEffectNode()
effectNode.shader = SKShader(source:
"""
void main() {
vec2 uv = v_tex_coord;
vec4 texel = texture2D(u_texture, uv);
vec4 color = texel;
vec4 outColor = texel;
// from top to bottom
if (uv.y > .8 / 2. + .5) { // bg color
color = i_color;
}
outColor = mix(texel, color, .6);
gl_FragColor = outColor;
}
"""
, uniforms: [
SKUniform(name: "i_color", vectorFloat4: vector_float4(1, 0, 0, 0))
])
scene?.addChild(effectNode)
effectNode.addChild(mediaNode)
}
}