Is there any way to apply a blur shader to a layer so that all its children are blurred. Im using this code atm, but it’s very slow and applying the shader directly to the layer doesn’t work. So I would like to know if there is an easier and more efficient way to achieve my goal.
void blurLayer(Layer* layer)
{
RenderTexture* renderTex = RenderTexture::create(layer->getContentSize().width, layer->getContentSize().height);
renderTex->begin();
layer->visit();
renderTex->end();
Sprite* sprite = renderTex->getSprite();
sprite->setAnchorPoint(Vec2(0, 0));
GLchar* fragSource = (GLchar*)String::createWithContentsOfFile(
FileUtils::getInstance()->fullPathForFilename("shaders/blur.fsh").c_str())->getCString();
auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, fragSource);
auto glProgramState = GLProgramState::getOrCreateWithGLProgram(program);
sprite->setGLProgramState(glProgramState);
auto size = sprite->getTexture()->getContentSizeInPixels();
sprite->getGLProgramState()->setUniformVec2("resolution", size);
sprite->getGLProgramState()->setUniformFloat("blurRadius", 8);
sprite->getGLProgramState()->setUniformFloat("sampleNum", 10.0f);
layer->addChild(sprite, 1000);
}
, I’m just using the blur shader from cpp-tests