简体   繁体   English

如何在SpriteKit中应用全屏SKEffectNode进行后期处理

[英]How to apply full-screen SKEffectNode for post-processing in SpriteKit

I'm trying out SpriteKit with the following setup: 我正在尝试使用以下设置SpriteKit:

  1. An SKScene with two child nodes used merely for grouping other nodes: foreground and background. 具有两个子节点的SKScene仅用于对其他节点进行分组:前景和背景。
  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. foreground是一个SKEffectNode,每当用户点击屏幕时,表示游戏元素的SKnode子类的新内容将作为子元素添加到其中。
  4. This SKNode subclass basically creates 3 SKShapeNodes and two labels: an outter circumference, an inner circumference, 2 labels and an inner quarter circumference. 此SKNode子类基本上创建3个SKShapeNodes和两个标签:外圆周,内圆周,2个标签和内圆周。 The inner quarter circumference has an SKAction that makes it rotate forever about its origin / center. 内部四分之一圆周具有SKAction,使其围绕其原点/中心永久旋转。

Now here's the issue, as long as foreground doesn't have any CIFilter or has shouldEnableEffects = NO, everything is fine. 现在这里是问题,只要前景没有任何CIFilter或者具有shouldEnableEffects = NO,一切都很好。 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: 但是当我尝试将CIGaussianBlur或CIBloom添加到前台时,我注意到两件事:

  1. The framerate drops to about 2fps. 帧速率降至约2fps。 Mind you, this happens even with as little as 6 nodes alive in the scene. 请注意,即使在场景中只有6个节点存在,也会发生这种情况。
  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: 这适用于一个节点:

    在此输入图像描述

And this is for 2 nodes: 这适用于2个节点:

在此输入图像描述

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. 在OpenGL ES 2中,人们可以通过基本上将整个帧缓冲区(所有对象)渲染到纹理,然后在该纹理上至少再做一次模糊等传递,然后将其添加到附加到的帧缓冲区中来进行模糊/开花。显示或组合与原始渲染回到帧缓冲区。 I'd expect SKEffectNode to work in a similar way. 我希望SKEffectNode以类似的方式工作。 However the cropping and the poor performance makes me think I might be using the effect node the wrong way. 然而,裁剪和糟糕的表现让我觉得我可能以错误的方式使用效果节点。 Any thoughts? 有什么想法吗?

It seems to be a bug with the SKEffectNode trying to apply a filter on children SKShapeNodes as far as I can tell. 据我所知,SKEffectNode尝试对子SKShapeNodes应用过滤器似乎是一个错误。 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. 我玩了这个并取得了你的成果,但是当我为SKSpriteNodes换出SKShapeNodes(使用一个简单的圆圈)时,不再出现裁剪。 It's a bug in that SKEffectNode doesn't handle the stroke of the SKShapeNode very well. 这是一个错误,因为SKEffectNode不能很好地处理SKShapeNode的笔划。 If you take off the stroke (lineWidth = 0) and give it a fill color, you'll see that there is no cropping. 如果你取下笔划(lineWidth = 0)并给它一个填充颜色,你会发现没有裁剪。

As for the frame rate, SKShapeNodes perform poorly. 至于帧速率,SKShapeNodes表现不佳。 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. 切换到SKSpriteNodes我之前提到过,当我在屏幕上有35个节点(iPhone 5)并且应用了过滤器时,我的fps从40增加到50。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM