0

I'm trying to do some simple lighting in a side scrolling game using an SKEffectnode. First I make a fullscreen sprite node with gray color, set it's blend mode to additive, and add it as a child to the effect node. Then I add sprite nodes with some light texture, also as children of the effect node. Finally I set the effect node's blend mode to multiply, and add it as a child to my scene. Something like this:

SKEffectNode *effectNode = [[SKEffectNode alloc] init];
SKSpriteNode *overlay = [SKSpriteNode spriteNodeWithColor: [SKColor grayColor] size: [self.size];
SKSpriteNode *light = [SKSpriteNode spriteNodeWithImageNamed: @"LightTexture.png"];
[overlay setBlendMode: SKBlendModeAdd];
[light setBlendMode: SKBlendModeAdd];
[effectNode addChild: overlay];
[effectNode addChild: light];
[effectNode setBlendMode: SKBlendModeMultiply];
[self addChild: effectNode];

So my problem is that the effect node's blend mode doesn't seem to be doing anything. Like it's stuck in alpha blend mode or something. However, if I set shouldRasterize to YES, the blend mode starts working like expected. Does anyone know why this is?

Also adding a fullscreen effect like this, with an effect node, totally destroys the frame rate. Especially if you start moving the effect node (or create a new one every frame). But i don't see any other way of doing lighting like this in sprite kit. I basically want to create a lighting mask every frame, and then multiply it to the scene's frame buffer. Is something like this possible using Sprite Kit? Or should I look into Cocos2d using custom shaders?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

0 Answers0