I am currently playing with shaders in Cocos2d. My goal is to apply a shader to the entire screen (except for one node and its children) to have an overlay menu while the game is blurry.
Now I found this tutorial for working with shaders in cocos2D, resulting in the following code
CCSprite *aSprite = [CCSprite spriteWithImageNamed:@"Default.png"];
aSprite.contentSizeType = CCSizeTypeNormalized;
aSprite.contentSize = CGSizeMake(0.5,0.5);
NSString *fullPath = [[NSBundle mainBundle] pathForResource:@"CSEEmboss" ofType:@"fsh"];
const GLchar * fragmentSource = (GLchar*) [[NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil] UTF8String];
aSprite.shaderProgram = [[CCGLProgram alloc] initWithVertexShaderByteArray:ccPositionTextureA8Color_vert
fragmentShaderByteArray:fragmentSource];
[aSprite.shaderProgram addAttribute:kCCAttributeNamePosition index:kCCVertexAttrib_Position];
[aSprite.shaderProgram addAttribute:kCCAttributeNameTexCoord index:kCCVertexAttrib_TexCoords];
[aSprite.shaderProgram link];
[aSprite.shaderProgram updateUniforms];
[aSprite.shaderProgram use];
[self.scene addChild:aSprite];
What really applies embossing to the sprite, however, when I add children to this sprite, the shader does not apply there, how can I do it? My scene contains many children, and adding and removing shaders with a loop for each child does not seem right to me.
source
share