-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative usage #19
Comments
Hi, sorry for the late reply and thanks for the input! I'm not very familiar with any other sampling methods available for cross-platform libGDX shaders (we stack with GLSL v1.20, if I'm not mistaken). Could you please explain your case in a bit more details? What exactly would you prefer to use to supply the initial image to the effect processing pipeline? |
Hi, originally I thought, why not read from the current screen? |
Actually, OpenGL does support reading from screen. public static void copyBackBufferToTexture(Texture tex) {
tex.bind();
Gdx.gl.glCopyTexImage2D(GL20.GL_TEXTURE_2D, 0, Format.toGlFormat(tex.getTextureData().getFormat()), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0); // WARNING: getFormat() doesn't always return correct format!
Gdx.gl.glBindTexture(GL20.GL_TEXTURE_2D, 0); // unbind
} You better use RGBA_8888 format, or you could run into troubles (libGDX being buggy). package com.betalord.sgx.rendering;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.Disposable;
import com.betalord.sgx.util.SGXFrameBuffer;
import com.crashinvaders.vfx.VfxManager;
import com.crashinvaders.vfx.effects.BloomEffect;
public class PostProcessing implements Disposable {
private VfxManager vfxManager;
private boolean enabled = true;
/** An intermediate FBO we use to copy back buffer contents to it and then pass it to gdx-vfx. */
private SGXFrameBuffer fbo;
private int width = 0;
private int height = 0;
public void init(int width, int height) {
this.width = width;
this.height = height;
vfxManager = new VfxManager(Pixmap.Format.RGBA8888, width, height);
BloomEffect bloom = new BloomEffect();
//bloom.applySettings(new BloomEffect.Settings(10, 0.85f, 1f, 0.85f, 1.1f, 0.85f));
bloom.applySettings(new BloomEffect.Settings(10, 0.1f, 1f, 0.85f, 1.1f, 1.85f));
vfxManager.addEffect(bloom);
fbo = new SGXFrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
}
public void process() {
if (!enabled)
return;
RenderUtils.copyBackBufferToTexture(fbo.getColorBufferTexture());
vfxManager.cleanUpBuffers();
vfxManager.useAsInput(fbo.getColorBufferTexture());
vfxManager.applyEffects(); // apply the effects chain to the captured frame
vfxManager.renderToScreen(); // render result to the screen
}
public void resize(int width, int height) {
if (this.width == width && this.height == height)
return;
this.width = width;
this.height = height;
vfxManager.resize(width, height);
// resize FBO:
if (fbo != null) fbo.dispose();
fbo = new SGXFrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
}
public void enable(boolean enable) {
this.enabled = enable;
}
public void enable() {
enable(true);
}
public void disable() {
enable(false);
}
public boolean isEnabled() {
return enabled;
}
@Override
public void dispose() {
if (vfxManager != null)
vfxManager.dispose();
if (fbo != null)
fbo.dispose();
}
} Note though, that gdx-vfx is possibly quite slow and could probably be greatly optimized. It uses several shader passes that could be reduced to a single pass, and some redundant (I believe) FBOs. But I haven't looked much into the code, just had a glance at it. |
@Betalord Sorry to be a bit rude but :
Yes, but that would be very inefficient in this context, it requires copy from GPU memory to CPU memory and send it back to the GPU memory, that's very bad in term of performances.
No. Libgdx works well with some other formats.
Yes, that's the proper way to do it.
No. The lib is good. It's just that post processing effects are greedy.
Yeah, that's probably why you say that :D |
The vfxManager uses a fbo to capture all activities and then adds all the effects.
This saves one copy operations.
But, currently fbos in libgdx do not support multi sampling.
So, I am forced to give up sampling support if I use vfxManager.
Can we have an alternative method that just copies the current screen without capturing in a fbo?
This way all draw operations can use multi sampling.
The text was updated successfully, but these errors were encountered: