Skip to content

Instantly share code, notes, and snippets.

@loveandsheep
Created December 28, 2016 02:42
Show Gist options
  • Save loveandsheep/012fb5c1a99d2b5be7f270539181d6c2 to your computer and use it in GitHub Desktop.
Save loveandsheep/012fb5c1a99d2b5be7f270539181d6c2 to your computer and use it in GitHub Desktop.
shader.begin();
shader.setUniformTexture("tex", buffer.getTexture(), 0);//白黒の図形を描画したofFbo
if (currentVid->isFrameNew())
shader.setUniformTexture("video", currentVid->getTexture(), 1);//ofVideoPlayerのテクスチャ
shader.setUniform4f("pl_1", pal.getColorArray(currentPalette)[0]);//配色用のofFloatColor配列
shader.setUniform4f("pl_2", pal.getColorArray(currentPalette)[1]);
shader.setUniform4f("pl_3", pal.getColorArray(currentPalette)[2]);
shader.setUniform4f("pl_4", pal.getColorArray(currentPalette)[3]);
shader.setUniform4f("pl_5", pal.getColorArray(currentPalette)[4]);
GLfloat verts[] = {0.0, 0.0, screen_width, 0.0, 0.0, screen_height, screen_width, screen_height};
//画面サイズの四角形を描画(無駄が無いように生GLで書いてますがofDrawRectangleでもいいかも)
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer (2, GL_FLOAT, 0, verts);
glTexCoordPointer (2, GL_FLOAT, 0, verts);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
shader.end();
uniform sampler2DRect tex; //図形のFboテクスチャ
uniform sampler2DRect video;//動画のテクスチャ
uniform vec4 pl_1;//パレット5色
uniform vec4 pl_2;
uniform vec4 pl_3;
uniform vec4 pl_4;
uniform vec4 pl_5;
void main(void)
{
vec2 st = gl_TexCoord[0].st;
vec4 palette[5];
palette[0] = pl_1;//base
palette[1] = pl_2;
palette[2] = pl_3;//accent
palette[3] = pl_4;
palette[4] = pl_5;
vec4 col = texture2DRect(tex, st);
vec4 vcl = texture2DRect(video, st / 1.5);
vec4 dst;
if (col.r == 0.2) //図形の明度が0.2の時だけ動画テクスチャ色を足す
col += vcl;
float gray = (col.r + col.g + col.b) / 3.0;
float index = min(gray * 5.0, 4.0);//明るさから使用する配色を選択
float mixer = mod(index, 1.0);
dst = mix(palette[int(index)],
palette[int(mod(index + 1.0, 5.0))],
mixer);//アンチエイリアス風処理
gl_FragColor = dst;//色確定
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment