マイペースなプログラミング日記

DTMやプログラミングにお熱なd-kamiがマイペースに書くブログ

シェーダで遊んでみる

色反転プログラムを改造して右半分と左半分で分けてみた。プログラムはこんな感じ

頂点シェーダー

varying vec2 pos;

void main(void)
{
    pos = gl_Vertex.xy;
    gl_Position = ftransform();
}

フラグメントシェーダー

uniform sampler2D image;
uniform int imgWidth, imgHeight;
varying vec2 pos;

void main(void)
{
    vec2 texCoord = vec2(pos.x / float(imgWidth), pos.y / float(imgHeight));
    vec4 col = texture2D(image, texCoord);

    if(int(pos.x) > imgWidth / 2){
        gl_FragColor.rgb = vec3(1.0) - col.rgb;
    }else{
        gl_FragColor.rgb = col.rgb;
    }
}