SpriteKit着色器崩溃iOS 9:SKDefaultShading,gl_FragCoord [英] SpriteKit shader crash iOS 9: SKDefaultShading, gl_FragCoord

查看:297
本文介绍了SpriteKit着色器崩溃iOS 9:SKDefaultShading,gl_FragCoord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚安装了iOS 9开放式测试版(版本3),现在我遇到了SpriteKit着色器的大量问题。在iOS 8上,以下代码工作正常:

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];

编辑:文件TheShader.fsh如下所示:

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;

在iOS 9上,控制台以这种格式喷出一堆警告:

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
             ^
}

似乎iOS9不是支持SKDefaultShading和gl_FragCoord。如何在不使用gl_FragCoord的情况下找到局部像素尺寸?

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:

如果我在上面注释出iOS9兼容性问题,那么问题会解决,但我没有任何着色器。

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.

推荐答案

我的自定义SKShader也停止在金属设备上的ios9中工作。

My custom SKShader also stopped working in ios9 on metal devices.

我能够使用v_tex_coord修复它以获取像素位置,并使用自定义均匀来发送精灵大小(似乎有一个错误,其中u_sprite_size不是传入。)

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.)

[SKUniform uniformWithName:@"u_fixed_size" floatVector2:GLKVector2Make(n.calculateAccumulatedFrame.size.width, n.calculateAccumulatedFrame.size.height)]

这篇关于SpriteKit着色器崩溃iOS 9:SKDefaultShading,gl_FragCoord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆