Giter Club home page Giter Club logo

Comments (4)

metaphore avatar metaphore commented on May 22, 2024

Well, I think you're just missing one small detail...

First of all, make sure you clean up the buffers (just like in the example). While it's most likely not gonna change anything, it will definitely help to figure out at which stage the rendering goes to the wrong buffer.

// Add this to the very beginning of the render() method.
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

// Put this before vfxManager.beginInputCapture()
vfxManager.cleanUpBuffers();

And then the actual problem comes to the surface - when you draw using vfxManager.renderToScreen() you draw an opaque picture to the screen (with black background). No wonder the old data get lost.

To solve this, you need to clean up the vfxManager buffers with transparent color. But keep in mind, that most of the built-in effects are implemented to be full-screen post effects. This means they are primarily designed to work with opaque images and output another opaque image. But I've been off the library for too long and can't remember exactly which ones are transparency compatible, and which ones are not. So you better experiment or write your own effects if you're looking for a specific image processing case.

To make buffers transparent, enable blending and use the clear color:

vfxManager.setBlendingEnabled(true);
vfxManager.cleanUpBuffers(Color.CLEAR);

Please let me know if it helps.

from gdx-vfx.

m-tosch avatar m-tosch commented on May 22, 2024

Thanks for the help. I updated my code. I think i see what you mean by "transparency compatible"

vfxManager.cleanUpBuffers();

grafik

vfxManager.setBlendingEnabled(true);
vfxManager.cleanUpBuffers(Color.CLEAR);

grafik

In the second image my map tiles are rendered now, however the effect looks quite different. Is this what you mean by "transparency compatible"? Can i mess with the SpriteBatch blending to improve the result or is something i'd have to write my own effect for in gdx_vfx?

from gdx-vfx.

metaphore avatar metaphore commented on May 22, 2024

Yeah, I think you'll have to play a little with how the effect output gets layered on top of the existing image to get the desired result. Luckily, in this particular case, it can be done with OpenGL blending modes and is completely outside of the gdx-vfx effect itself.

To me, the circle on the second image looks like it has premultiplied alpha qualities. It's worth trying to render it with different blending. Try to switch to the premultiplied mode before and reset the OpenGL state after rendering the effect to the screen.

// Enable PMA blending.
Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);

vfxManager.renderToScreen();

// Reset to non-PMA blending.
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

from gdx-vfx.

m-tosch avatar m-tosch commented on May 22, 2024

I think it's still not the same as in the image above with the black background, but it looks a little better now. In the meantime i've been writing some of my own shaders and implemented them via the default libgdx ShaderProgram class. Most of what i need i can cover with this.
grafik

Since you answered my original question about the combination of gdx_vfx and SpriteBatch rendering i'll close this issue.

Thank you very much :)

from gdx-vfx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.