目前我正在Cocos2d中着色器周圍。我的目標是在整個屏幕上應用着色器(除了一個節點和它的子節點),以便在遊戲模糊時製作疊加菜單。Cocos2d v3在子節點上應用着色器
現在我發現this tutorial與在cocos2d着色器導致下面的代碼工作
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];
這的確適用印紋的精靈,但是當我添加子到精靈,不應用着色器在那裏,我應該怎麼做呢?我的場景包含許多孩子,添加和刪除着色器的循環給每個孩子似乎並不適合我。
是啊,這是我們去的方式。僅使用iOS庫來捕獲屏幕和Core Graphics以模糊。 – Matthijn