如何在SpriteKit中应用全屏SKEffectNode进行后期处理 [英] How to apply full-screen SKEffectNode for post-processing in SpriteKit

查看:171
本文介绍了如何在SpriteKit中应用全屏SKEffectNode进行后期处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下设置尝试SpriteKit:

I'm trying out SpriteKit with the following setup:


  1. 带有两个子节点的SKScene仅用于分组其他
    节点:前景和背景。

  2. 背景到目前为止是空的,但最终会保留一些
    类型的背景精灵/图层。

  3. 前景是一个SKEffectNode,每当用户点击
    屏幕时,表示游戏
    元素的SKnode子类的新intance将作为子元素添加到其中。

  4. 这个SKNode子类基本上创建了3个SKShapeNodes和两个标签:一个超出
    的圆周,一个内圆周,两个标签和一个内圆周。内部周长有一个SKAction,
    使它永远围绕其原点/中心旋转。

  1. An SKScene with two child nodes used merely for grouping other nodes: foreground and background.
  2. background is really empty as of now, but would eventually hold some type of background sprite / layers.
  3. foreground is a SKEffectNode and whenever the user taps on the screen, a new intance of a SKnode subclass which represents a game element is added as child to it.
  4. This SKNode subclass basically creates 3 SKShapeNodes and two labels: an outter circumference, an inner circumference, 2 labels and an inner quarter circumference. The inner quarter circumference has an SKAction that makes it rotate forever about its origin / center.

现在问题在于只要前景没有任何CIFilter或者具有shouldEnableEffects = NO,一切都很好。也就是说,我可以点击屏幕,我的游戏元素被实例化并添加到主场景中。但是当我尝试将CIGaussianBlur或CIBloom添加到前台时,我注意到两件事:

Now here's the issue, as long as foreground doesn't have any CIFilter or has shouldEnableEffects = NO, everything is fine. That is, I can tap on the screen and my game elements are instantiated and added to the main scene. But the minute I try adding a CIGaussianBlur or CIBloom to the foreground, I notice two things:


  1. 帧速率降至约2fps。请注意,即使使用
    也只会在场景中活动6个节点。

  2. 效果似乎是不断裁剪其内容或调整
    这是框架。也就是说,如果我有一个节点,全屏效果
    似乎尝试不断裁剪或调整其边界到保持所有节点所需的最小
    区域。这是针对一个节点:

  1. The framerate drops to about 2fps. Mind you, this happens even with as little as 6 nodes alive in the scene.
  2. The effect seems to be constantly cropping its contents or adjusting it's frame. That is, if I have one node, the "full screen" effect seems to try and constantly crop or adjust its bounds to the minimum area required to hold all nodes. This is for one node:

这是2个节点:

在OpenGL ES 2中,通过基本上将整个帧缓冲区(所有对象)渲染到纹理,然后在该纹理上至少再进行一次模糊等操作,然后将其添加到附加到显示器的帧缓冲区中或者组成用原始渲染回到帧缓冲区。我希望SKEffectNode以类似的方式工作。然而,裁剪和糟糕的表现让我觉得我可能以错误的方式使用效果节点。有什么想法吗?

In OpenGL ES 2, one would do a post blur / bloom by basically rendering the whole framebuffer (all objects) to texture, then doing at least one more pass to blur,etc on that texture and then either present that in the framebuffer attached to the display or compose that with the original render back to the framebuffer. I'd expect SKEffectNode to work in a similar way. However the cropping and the poor performance makes me think I might be using the effect node the wrong way. Any thoughts?

推荐答案

SKEffectNode尝试对儿童SKShapeNodes应用过滤器似乎是个错误告诉。我玩了这个并取得了你的成果,但是当我为SKSpriteNodes切换SKShapeNodes(使用一个简单的圆圈)时,不再出现裁剪。这是一个错误,因为SKEffectNode不能很好地处理SKShapeNode的笔划。如果你取消笔画(lineWidth = 0)并给它一个填充颜色,你会发现没有裁剪。

It seems to be a bug with the SKEffectNode trying to apply a filter on children SKShapeNodes as far as I can tell. I played around with this and achieved your results, but when I switched out the SKShapeNodes for SKSpriteNodes (using a simple png of a circle) the cropping no longer appears. It's a bug in that SKEffectNode doesn't handle the stroke of the SKShapeNode very well. If you take off the stroke (lineWidth = 0) and give it a fill color, you'll see that there is no cropping.

至于帧速率,SKShapeNodes表现不佳。切换到SKSpriteNodes我之前提到过,当我在屏幕上有35个节点(iPhone 5)并且应用了过滤器时,我的fps从40增加到50。

As for the frame rate, SKShapeNodes perform poorly. Doing the switch to SKSpriteNodes I mentioned earlier boosted my fps from 40 to 50 when I had 35 nodes on the screen (iPhone 5) with the filter applied.

这篇关于如何在SpriteKit中应用全屏SKEffectNode进行后期处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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