libgdx-contribs
libgdx-contribs copied to clipboard
Apply effects only on specific textures
First of all, thanks for such a great lib, it's a life-saver, really!
I have a tile-based game and what I'm trying to do is enabling some post-processing effect in the middle of the rendering process, without affecting the previously rendered textures or the next ones. For example, I render floor and walls tiles with Bloom, then monsters with Bloom and MotionBlur, and then some other textures with just Bloom again.
Here is a pseudo code of what I'm doing:
private SpriteBatch batch;
private PostProcessor postProcessor;
private MotionBlur blur;
// Create PostProcessor with a disabled MotionBlur effect
public void create() {
ShaderLoader.BasePath = "shaders/post-processing/";
postProcessor = new PostProcessor(false, false, SystemUtils.IS_OS_DESKTOP);
blur = new MotionBlur();
blur.setEnabled(false);
postProcessor.addEffect(blur);
}
public void render() {
postProcessor.capture();
batch.begin();
... // draw some textures. MotionBlur effect is disabled here
batch.end();
postProcessor.render();
blur.setEnabled(true);
postProcessor.capture();
batch.begin();
... // draw some textures with MotionBlur enabled
batch.end();
postProcessor.render();
blur.setEnabled(false);
postProcessor.capture();
batch.begin();
... // draw some textures. MotionBlur is no longer enabled
batch.end();
postProcessor.render();
}
What happens is the first batch of textures is not rendered, or is overwritten by the MotionBlur rendering process. What am I doing wrong? Is it even possible to achieve what I'm suggesting?
Thanks for the attention.