We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Of course you can use shaders on a PGraphics.
But you need to useYou can use it exactly like with PApplet.shader()
instead offilter()
, which slows the program slightly.If there was some sore of
filter(NONE)
or, this would've been much easier.shader(DEFAULT)
EDIT -
resetShader()
exists. So if you useshader()
instead offilter()
, you can do what you want.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.