bool HelloWorld::init() {
if(!Layer::init()) {
return false;
}
Sprite* sprite_blur = Sprite::create("checkbox_checked.png");
GLchar * fragSource = nullptr;
fragSource = (GLchar*)String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename("blur.fsh").c_str())->getCString();
sprite_blur->setShaderProgram(GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, fragSource));
sprite_blur->setGLProgramState(GLProgramState::getOrCreateWithGLProgram(sprite_blur->getGLProgram()));
sprite_blur->getGLProgramState()->setUniformVec2("resolution", sprite_blur->getTexture()->getContentSizeInPixels());
sprite_blur->getGLProgramState()->setUniformFloat("blurRadius", 10.0f);
sprite_blur->getGLProgramState()->setUniformFloat("sampleNum", 7.0f);
sprite_blur->setPosition(400, 400);
addChild(sprite_blur);
//==blur.fsh==
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform vec2 resolution;
uniform float blurRadius;
uniform float sampleNum;
vec4 blur(vec2);
void main(void)
{
vec4 col = blur(v_texCoord); //* v_fragmentColor.rgb;
gl_FragColor = vec4(col) * v_fragmentColor;
}
vec4 blur(vec2 p)
{
if (blurRadius > 0.0 && sampleNum > 1.0)
{
vec4 col = vec4(0);
vec2 unit = 1.0 / resolution.xy;
float r = blurRadius;
float sampleStep = r / sampleNum;
float count = 0.0;
for(float x = -r; x < r; x += sampleStep)
{
for(float y = -r; y < r; y += sampleStep)
{
float weight = (r - abs(x)) * (r - abs(y));
col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)) * weight;
count += weight;
}
}
return col / count;
}
return texture2D(CC_Texture0, p);
}
'기타' 카테고리의 다른 글
Widows 10 - Speech Recognition Error 해결법 (0) | 2023.12.08 |
---|---|
형상관리툴 종류 (0) | 2019.08.07 |
[Git] 전체 히스토리에서 특정 파일&특정 디렉토리 전부 삭제 (0) | 2019.02.26 |
Nox 블루스크린 문제 - ( Windows - Hyper-V 사용 해제 ) (0) | 2019.01.07 |