Frame Buffer & Cameras - Scene Transitions - Black Flicker

Frame Buffer & Cameras - Scene Transitions - Black Flicker
0.0 0

#1

Hoping someone can help me out here.

I’ve adjusted my main game scene to use a separate camera with a frame buffer so I can do post processing effects, but I’ve noticed that during scene transitions the screen is whatever I’ve set the clear color to be (default black) before popping in once they’re done. I figure it’s just because the sprite it’s rendering to is empty and therefore black, but as it is it kinda defeats the purpose of having a scene transition.

Does anyone have any suggestions for how to fix this? Note how the screen goes black while the UI fades.

When I set the postProcess sprite to not be visible it functions as you would expect, but that’s a problem if I set the sprite to do some post processing because, well, even if I set it to be visible after the transition is done, the effect will then “pop in”.

tempLayer = Layer::create();
tempLayer->addChild(game);
this->addChild(tempLayer);
tempLayer->setCameraMask((unsigned short)CameraFlag::DEFAULT);

//framebuffer
auto frameBuffer = cocos2d::experimental::FrameBuffer::create(0, size.width, size.height);
frameBuffer->setClearColor(Color4F::BLACK);

//render target
cocos2d::experimental::RenderTarget* renderTarget = cocos2d::experimental::RenderTarget::create(size.width, size.height);
frameBuffer->attachRenderTarget(renderTarget);
renderTarget->getTexture()->setAliasTexParameters();

//stencil depth
auto depth = cocos2d::experimental::RenderTargetDepthStencil::create(size.width, size.height);
frameBuffer->attachDepthStencilTarget(depth);

//sprite
cocos2d::Texture2D* texture = frameBuffer->getRenderTarget()->getTexture();
postProcess = cocos2d::Sprite::createWithTexture(texture);
postProcess->setFlippedY(true);
postProcess->setAnchorPoint(Vec2::ZERO);
addChild(postProcess);

//camera
cocos2d::Camera* camera = cocos2d::Camera::create();
camera->setCameraFlag(CameraFlag::DEFAULT);
camera->setDepth(0);
camera->setFrameBufferObject(frameBuffer);
tempLayer->addChild(camera);

Thanks for any help.


#2

Hey! You definitely should have another camera which would draw postProcess texture to the screen buffer not to the render buffer.


#3

Hey! Thanks a lot for the suggestion! Do you know how to set it up to render to the screen buffer?