【问题标题】:CIFilter GaussianBlur seems to be broken on iOS9.x (used with SKEffectNode)CIFilter GaussianBlur 似乎在 iOS9.x 上被破坏(与 SKEffectNode 一起使用)
【发布时间】:2016-02-01 01:11:45
【问题描述】:

我正在尝试使用以下 sn-p 创建模糊效果:

  let glowEffectNode = SKEffectNode()
  glowEffectNode.shouldRasterize = true

  let glowSize = CGSize(width: barSize.width, height: barSize.height)
  let glowEffectSprite = SKSpriteNode(color: barColorData.topColor, size: glowSize)
  glowEffectNode.addChild(glowEffectSprite)

  let glowFilter = CIFilter(name: "CIGaussianBlur")
  glowFilter!.setDefaults()
  glowFilter!.setValue(5, forKey: "inputRadius")

  glowEffectNode.filter = glowFilter

当然,在 iOS 8.x 上它可以完美运行,但从 iOS 9.x(在 9.0 和 9.1 上都尝试过)模糊无法正常工作。 (在模拟器上,节点似乎有点透明但绝对不模糊,在设备上它似乎模糊但被裁剪,并且从其中心位置也有偏移:/)

有没有使用 CIFilter 快速解决此问题的方法?

【问题讨论】:

  • CIFilter一般(即核心图像框架)损坏了,还是仅与SKEffectNode(SpriteKit 框架)有关?根据答案,我会稍微修改问题的标题。另外,感谢您的解决方案。
  • @NicolasMiari 我只用 SpriteKit 测试过
  • 我想知道它在 Mac OS 前端的表现如何......
  • 据我所知,SpriteKit/iOS 9 中出现了很多问题。通过采用更好的做法可以避免一些问题(即,之前碰巧没有出现问题的东西,但是应该有),而其他的似乎是来自 Apple 的彻底错误。

标签: sprite-kit ios9 cifilter


【解决方案1】:

我对此进行了更多的摆弄并找到了解决方案......

首先,似乎使用奇数作为模糊半径会导致整个节点以偏移量 (???) 进行渲染,因此例如使用 10 可以解决偏移量问题。

其次,模糊似乎被裁剪了,因为整个节点都是渲染的精灵,而对于模糊效果,你需要一个额外的空间,所以我使用透明精灵作为额外的空间,下面的代码 sn-p 现在可以工作:

let glowEffectNode = SKEffectNode()
glowEffectNode.shouldRasterize = true

let glowBackgroundSize = CGSize(width: barSize.width + 60, height: barSize.height + 60)
let glowSize = CGSize(width: barSize.width + 10, height: barSize.height + 10)
let glowEffectSprite = SKSpriteNode(color: barColorData.topColor, size: glowSize)
glowEffectNode.addChild(SKSpriteNode(color: SKColor.clearColor(), size: glowBackgroundSize))
glowEffectNode.addChild(glowEffectSprite)

let glowFilter = CIFilter(name: "CIGaussianBlur")
glowFilter!.setDefaults()
glowFilter!.setValue(10, forKey: "inputRadius")

glowEffectNode.filter = glowFilter

我应该提到我正在使用 view.textureFromNode(glowEffectNode) 从这个节点创建纹理以提高效率,但我尝试使用节点本身并且问题仍然存在,所以无论如何以上都应该工作

【讨论】:

    猜你喜欢
    • 2015-10-03
    • 2021-09-22
    • 2020-02-22
    • 1970-01-01
    • 2015-02-18
    • 2019-08-07
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多