void MaskShaderEffect::buildCustomUniforms() { GLProgram *shader = getShaderProgram(); _uniformTouchPoint = shader->getUniformLocation("touchPoint"); #ifndef ES_30_SUPPORT _uniformCoefficient = shader->getUniformLocation("coefficient"); _uniformColor = shader->getUniformLocation("color"); #endif }
bool BlurNode::init() { if (!Node::init()) return false; // read and add my shader GLProgram* program = GLProgram::createWithFilenames("ccShader_blur.vert", "BlurNormal.frag"); if (!program) return false; setShaderProgram(program); // get uniform variable location _uSolutionLocation = program->getUniformLocation("u_resolution"); // load texture2D _texture = TextureCache::getInstance()->addImage("cballs.png"); if (!_texture) return false; _texture->retain(); setContentSize(_texture->getContentSize()); Size size = getContentSize(); // init vertices array and texCoord array _vertices.push_back(Point::ZERO); _vertices.push_back(Point(size.width, 0)); _vertices.push_back(Point(0, size.height)); _vertices.push_back(Point(size.width, size.height)); _texCoord.push_back(Point(0, 1)); _texCoord.push_back(Point(1, 1)); _texCoord.push_back(Point::ZERO); _texCoord.push_back(Point(1, 0)); scheduleUpdate(); return true; }
void BlurSpriteXY::initWeights() { m_uPixelSize->setData(m_pixelSize); m_uRadius->setData(m_blurSize); int end = m_blurSize * 2 + 1; m_weights.resize(end); const float pi = acosf(-1.0f); float sq2 = sqrt(2.0f * pi); float sqSigma2 = GameMathHelp::squre(m_simga); float sum = 0.0f; for (int i = 0; i < end; i++) { m_weights[i] = 1.0f / (m_simga * sq2) * exp(-GameMathHelp::squre(i - m_blurSize) / (2 * sqSigma2)); sum += m_weights[i]; } for (int i = 0; i < end; i++) m_weights[i] /= sum; GLProgram *glp = getGLProgram(); GLint weightLoc = glp->getUniformLocation("u_weights"); glUniform1fv(weightLoc, end, m_weights.data()); m_weightNeedInit = false; //log("init weight, sum = %f, end = %d", sum, end); }