@bubba
Thanks for answering :) !
I finally found a fast and acceptable solution based on lightmap :), here some explanations if someone needs its, and any advices to improve it are welcome :) :
In my main layer, i have added a custom RenderTexture node as child, i use it to generate lightmap. It have this method added :
-(void)beginWithColor:(float)r g:(float)g b:(float)b a:(float)a
{
CC_DISABLE_DEFAULT_GL_STATES();
// Save the current matrix
glPushMatrix();
CGSize texSize = [texture contentSize];
// Calculate the adjustment ratios based on the old and new projections
CGRect frame = [[[CCDirector sharedDirector] openGLView] frame];
float widthRatio = frame.size.width / texSize.width;
float heightRatio = frame.size.height / texSize.height;
// Adjust the orthographic propjection and viewport
glOrthof((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1);
glViewport(0, 0, texSize.width, texSize.height);
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);//Will direct drawing to the frame buffer created above
glDisable(GL_DITHER);
CC_ENABLE_DEFAULT_GL_STATES();
glColorMask(TRUE, TRUE, TRUE, TRUE);
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
It's a method that allow to clear color of the TextureRender node and begin just after that, i don't know if it speed up anything...
In made every "lighting" object inherit from a custom CCSprite called lightNode, it add :
A CCSprite halloCouleur (the glow pict) as a retain property to the object, with the following BlendFunc : [halloCouleur setBlendFunc:(ccBlendFunc) {GL_SRC_ALPHA,GL_ONE}];
And too methods :
//This method draw the glow of the object to screen
-(void)drawHalloCouleur
{
[halloCouleur setVisible:TRUE];
[halloCouleur visit];
[halloCouleur setVisible:FALSE];
}
//As the glow is not a child of the object, this method update glow position
-(void)setPosition:(CGPoint)newPosition
{
[super setPosition:newPosition];
halloPict.sprite.position = self.position;
}
In my main tick function, i test if any light object is moving/changing color/fading (depending on what can change in my objects and affect background light), if their is any change, moreover, if their is change, i don't update every frame but only at 20 fps (i use a simple counter for that), i draw the new background like that :
-(void)renderBack
{
//Render the new texture
//Clear texture with the "ambient" light color
[renderTexture beginWithColor:0.1f g:0.1f b:0.1f a:1.0f];
//Draw my heroes glow
//Every glow will be "added" to current pixel color, depending of their alpha, the more "transparent" the light picture is, the less it impact lighting.
for(heros* tmpHero in myHeroes)
{
[tmpHero drawHalloCouleur];
}
//Draw some other object glow
for(filterDoor* fd in colorFilters)
{
[fd drawHalloCouleur];
}
//And draw the background image
//The background sprite as this blend function : [background setBlendFunc:(ccBlendFunc) {GL_ZERO, GL_SRC_COLOR}];
//So pixel of the background will be affected by the light-mapping as it should, red lights will only light red pixel of the picture, etc...
[background visit];
//End of the rendering
[renderTexture end];
}
Everything running fast (60fps/59.2fps when moving ;)) on my iPod Touch 2G, with 8 lights.
Hope it will help someone.