Fading without shadows/artifacts; rounding issues

edited November 2013 in How To...

I've recently worked on my first complete project with Processing, a simple paint application where the strokes of different colors eventually fade completely to black.

Using the common methods which simply draw a fullscreen rect with an alpha value, it seems it is inevitable that there will always be some shadows/artifacts left behind from the strokes.

This example is from the old forum: http://forum.processing.org/one/topic/background-will-not-fade-to-white.html

The suggested improved method works, but is extremely slow on the systems I tried it on at fullscreen 1366x768. These systems had relatively basic integrated intel based video cards on i5/i7 systems. If this is the suggested method to avoid these ghosting issues, will a dedicated desktop video card allow for much higher/smoother framerates? The smoothness of the drawing depends on there being a high framerate, hopefully of at least 60fps.

Answers

  • Answer ✓

    I get 60 fps using a shader, 4 year old intel graphics:

    fadeWithShader.pde

    PShader fade;
    
    void setup() {
      size(1366, 768, P2D); 
      background(0);
      strokeWeight(3);
      stroke(255);
      fade = loadShader("fade.glsl");
    }
    void draw() {
      filter(fade);
      if(mousePressed) { 
        line(mouseX, mouseY, pmouseX, pmouseY);
      }
      println(frameRate); 
    }
    

    fade.glsl

    #define PROCESSING_TEXTURE_SHADER
    
    uniform sampler2D texture;
    varying vec4 vertColor;
    varying vec4 vertTexCoord;
    
    void main(void) {
        vec3 curr = texture2D(texture, vertTexCoord.st).rgb;
        gl_FragColor = vec4(curr.r-0.005, curr.g-0.005, curr.b-0.005, 1.0) * vertColor;
    }
    
  • edited November 2013

    Excellent. This works as intended. The glsl shader was not implemented in the previous solution. Thanks!

Sign In or Register to comment.