Blur filter on one object?

edited March 2017 in GLSL / Shaders

Hi everyone. Here's the BlurFilter shader example from Processing. Is there any way to apply a shader to one specific object, the same way that fill() works, or can shaders only apply to the entire final image drawn? For example, placing a filter function between two primitives makes no difference to the final image.

I've tried googling this but can't seem to find the right terms. I'm creating a solar system model and want to apply a blur/glow filter to the sun but to no other objects.

Thanks!


PShader blur;

void setup() {
  size(640, 360, P2D);
  blur = loadShader("blur.glsl"); 
  stroke(255, 0, 0);
  rectMode(CENTER);
}

void draw() {
  rect(mouseX, mouseY, 150, 150); 
  filter(blur);  
  ellipse(mouseX, mouseY, 100, 100);
}

Answers

  • I wonder if you could apply the shader to a PGraphics object and then draw it. thinking here loud btw...

    Kf

  • edited March 2017

    Of course you can use shaders on a PGraphics. But you need to use shader() instead of filter(), which slows the program slightly. You can use it exactly like with PApplet.

  • edited March 2017 Answer ✓

    If there was some sore of filter(NONE) or shader(DEFAULT), this would've been much easier.
    EDIT - resetShader() exists. So if you use shader() instead of filter(), you can do what you want.

  • Answer ✓

    It is not possible to add a blur filter onto a shape, because a blur filter needs a texture to work on. So you first have to draw the shape onto an own PGraphics object, filter that, and then make the composing. First draw the graphics, then your stuff which should not be blurred.

    But check out my newest project. It is a library to add post effects to PGraphics objects, but very easy. A blur filter is also implemented.

    https://github.com/cansik/processing-postfx

  • thanks everyone!

  • Yes, @cansik's library will do much of the job for you and you wouldn't have to break your head over understanding all this.

Sign In or Register to comment.