I'm trying out SpriteKit with the following setup:
- An SKScene with two child nodes used merely for grouping other nodes: foreground and background.
- background is really empty as of now, but would eventually hold some type of background sprite / layers.
- 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.
- 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.
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:
- The framerate drops to about 2fps. Mind you, this happens even with as little as 6 nodes alive in the scene.
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:
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?
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.
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.
来源:https://stackoverflow.com/questions/18937461/how-to-apply-full-screen-skeffectnode-for-post-processing-in-spritekit