SpriteKit shader crash iOS 9: SKDefaultShading, gl_FragCoord

前端 未结 4 2122
小蘑菇
小蘑菇 2021-02-20 02:51

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:

_fontS         


        
4条回答
  •  时光取名叫无心
    2021-02-20 03:40

    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
    

提交回复
热议问题