-
-
Save t-takasaka/848b46b7e1d92c7a62c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sprite *spriteBack = m_textureBack->getSprite(); | |
Sprite *spriteFront = m_textureFront->getSprite(); | |
GLint defFrameBuf = 0; //デフォルトのFBOを退避 | |
GLuint colorBufBack = spriteBack->getTexture()->getName(); | |
GLuint colorBufFront = spriteFront->getTexture()->getName(); | |
GLuint frameBufBack = 0, frameBufFront = 0; | |
glGenFramebuffers(1, &frameBufFront); | |
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defFrameBuf); | |
glBindFramebuffer(GL_FRAMEBUFFER, frameBufFront); | |
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBufFront, 0); | |
GLenum framebufStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); | |
if(framebufStatus != GL_FRAMEBUFFER_COMPLETE){} //error処理 | |
glClearColor(0, 0, 0, 0); | |
glClear(GL_COLOR_BUFFER_BIT); | |
//FBOにフレーム内背景を描画 | |
m_programBack->use(); | |
const GLfloat pos[] = { -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f }; | |
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)pos); | |
glBindTexture(GL_TEXTURE_2D, colorBufBack); | |
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | |
//FBOにフレーム内前景を描画 | |
DrawProfileCocos2D::preDraw(); | |
m_live2DModel->update(); | |
m_live2DModel->draw(); | |
DrawProfileCocos2D::postDraw(); | |
//サーフェイスにFBOを描画 | |
glBindTexture(GL_TEXTURE_2D, 0); | |
glBindFramebuffer(GL_FRAMEBUFFER, defFrameBuf); | |
glDeleteFramebuffers(1, &frameBufFront); | |
spriteFront->draw(renderer, transform, flags); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform vec2 u_center; | |
uniform float u_width; | |
varying vec2 v_texCoord; | |
void main(){ | |
vec2 pos = v_texCoord - u_center; | |
vec4 color = vec4(0.0); | |
int count = 10; | |
for(int i = 0; i < count; i++){ | |
float scale = 1.0 + u_width * (float(i) / float(count - 1)); | |
color += texture2D(CC_Texture0, pos * scale + u_center); | |
} | |
gl_FragColor = color / float(count); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m_programFront = new GLProgram(); | |
m_programFront->retain(); | |
m_textureFront->getSprite()->setGLProgram(m_programFront); | |
m_programFront->initWithVertexShaderFilename("shaders/radial_blur.vsh","shaders/radial_blur.fsh"); | |
m_programFront->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); | |
m_programFront->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); | |
m_programFront->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); | |
m_programFront->link(); | |
m_programFront->updateUniforms(); | |
//テクスチャサイズ。m_resoScaleは解像度の調整用 | |
m_programFront->setUniformLocationWith2f(m_programFront->getUniformLocationForName("u_size"), width * m_resoScale, height * m_resoScale); | |
//集中線の中心 | |
m_programFront->setUniformLocationWith2f(m_programFront->getUniformLocationForName("u_center"), 0.5f, 0.5f); | |
//集中線のサンプリングする幅 | |
m_programFront->setUniformLocationWith1f(m_programFront->getUniformLocationForName("u_width"), -0.1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute vec4 a_position; | |
attribute vec2 a_texCoord; | |
varying vec2 v_texCoord; | |
void main(){ | |
gl_Position = CC_PMatrix * a_position; | |
v_texCoord = a_texCoord; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment