We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm fairly new to shaders and am beginning to like them because of their capabilities in terms of speed an parallelism. What I'd like to do is to apply a certain shader not to the whole sketch, but only to a certain PGraphics image, is that possible?
When using filter()
, everything works fine. I just apply it after drawing everything else to the PGraphics.
When trying to use shader()
, I call pg.shader(myShader)
before drawing any objects to the PGraphics (because that's how shaders work, right?), and in between pg.beginDraw()
and pg.endDraw()
, but without success. I've tried other combinations, but they don't work either.
What am I missing?
Answers
we hate it when people say this. what doesn't work? in what way doesn't it work?
post a runnable example.
Sorrrrry, by "not working" I mean that the shader is not applied, it acts like the default shader is applied.
Here's an example of what's working fine:
and here's an example that's not applying the shader:
With which I'm getting a warning: Your shader needs to be of COLOR type to render this geometry properly, using default shader instead.
The difference between the two codes is in the lines 10 and 20 where I'm changing places where the shader is applied (in the first one I apply it to the whole sketch, and in the other I'm applying it to the PGraphics object).
Here's the shader code, I'm not sure where should apply the suggested fix that I'm getting in the warning message.
re: COLOR
have you read this:
https://processing.org/tutorials/pshader/
specifically the section: "Types of shaders in Processing"
where are you setting the texture? i don't think you are, hence it thinking you have a color shader rather than a texture shader.
Uh.. I get what you're saying and am realizing that this is more complicated than I thought. I see the COLOR/TEXTURE problem, but I'm not sure how to fix it. Should I change the shader code or the Processing code?
I guess I should just read the Shaders tutorial more thoroughly.
But I'm not sure what the texture should be. In the examples it's clear, but if you just want to blur things you have drawn using geometry it's not so obvious.
Maybe pass the (unblurred) pg in as the texture, applying the blur in draw? Think you may need to draw using a textured PShape rather than image() in draw ()