shader to make white background transparent

For one of my sketches I need to take a black an white PImage and remove all the white pixels. I did it using the usual pixel array method but this slows down my sketch considerably (its already computing the physiscs for 1000 particles). I really want to learn how to use the GLSL shaders but as I'm not skilled in C thats going to take some time. For now can someone give me a quick solution?




  • Answer ✓

    Figured it out. In case anyone else ever needs this, here's a simple shader I made:

    #ifdef GL_ES
    precision mediump float;
    precision mediump int;
    varying vec4 vertTexCoord;
    uniform sampler2D texture;
    void main(void)
        vec3 col = texture2D(texture,;
        float a = 1.0 - col.r ; // make white transparent
        col.rgb = 1.0 - col.rgb; // invert if wanted
        gl_FragColor = vec4(col, a);
Sign In or Register to comment.