Bloom lib.

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

Re: Bloom lib.

Postby kalle_h » Mon Feb 06, 2012 4:02 pm

Sippolo wrote:
kalle_h wrote:http://dl.dropbox.com/u/10960490/bloom.jar

Damn I am feeling stypid. I did't active texture_2d that is't problem usually becouse its active on defaul in most case but spriteBatch does disable it's after batch end. Thanks for awesome bug report. That should be fixed for now.


It was not that awesome really, just wanted to try this pretty contribution :D
Thank YOU for all your effort!
Unfortunately, the same snippet as before, shows again a black screen all the time :(

Just out of testing curiosity, I tried commenting either the bloom.render() instruction or the bloom.capture() instruction, and in both cases it still shows just a black screen all the time.
Also, I've tried rendering some fonts and some lights (with box2dlights) AFTER the bloom.render(), and very strangely the text is not displayed, but the lights are.
It looks like the bloom took out all the texture rendering.


Box2dlights and bloom lib wont work very well together. Both use fbo:s and do some blurring so there is almoust nothing to gain using bloom lib same time with box2dlights.

If you give minimal test case where black screen occur I can test it and try to find bugs.
kalle_h
 
Posts: 636
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby Sippolo » Mon Feb 06, 2012 5:37 pm

I give you a very simple test case I used to test it, just rendering one sprite.
If you comment the two bloom instructions in the render() method, you can see the sprite is correctly rendered, otherwise, it's black screen.

TestScreen.java
Code: Select all
package com.bloomtest;

import bloom.Bloom;

import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class TestScreen implements Screen {
   
   private Bloom bloom;
   private OrthographicCamera camera;
   private SpriteBatch batch;
   private Sprite sprite;

   @Override
   public void render(float delta) {
      camera.update();
      bloom.capture();
      batch.begin();
      sprite.draw(batch);
      batch.end();
      bloom.render();
   }

   @Override
   public void resize(int width, int height) {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void show() {
      bloom = new Bloom();
      bloom.setClearColor(0, 0, 0, 1);
      sprite = new Sprite(new Texture("data/sprite.png"));
      sprite.setBounds(200, 100, 200, 200);
      camera = new OrthographicCamera(480, 320);
      camera.position.set(240, 160, 0);
      batch = new SpriteBatch();
   }

   @Override
   public void hide() {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void pause() {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void resume() {
      bloom.resume();
   }

   @Override
   public void dispose() {
      bloom.dispose();
   }

}



DesktopStarter.java
Code: Select all
package com.bloomtest;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

public class DesktopStarter {

   /**
    * @param args
    */
   public static void main(String[] args) {
      LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
      config.title = "Bloom Test";
      config.width = 800;
      config.height = 480;
      config.useGL20 = true;
      new LwjglApplication(new TestScreen(), config);
   }

}



And here is the png I used:

sprite.png
sprite.png (99.47 KiB) Viewed 1708 times



Here what I get by just commenting the instructions bloom.capture() and bloom.render():

working.png
working.png (85.41 KiB) Viewed 1708 times


And here is what I get by uncommenting those lines again, activating the bloom:

not working.png
not working.png (41.2 KiB) Viewed 1708 times



That's all ^^
Sippolo
 
Posts: 67
Joined: Thu Jan 12, 2012 12:19 pm
Location: Italy

Re: Bloom lib.

Postby Jan » Tue Feb 07, 2012 10:28 pm

Can we get the sourcecode for the original example?

(The one in the original post)
Jan
 
Posts: 7
Joined: Thu Feb 02, 2012 2:58 am

Re: Bloom lib.

Postby kalle_h » Wed Feb 08, 2012 4:05 pm

Sippolo: Finally fixed the bug. It was pain to found. Source was inside of SpriteBatch. SpriteBatch allways bind to current texture unit but use texture unit 0. I did solved this by making sure that last texture unit used inside of bloom is 0.


Jan: I am workin on something that can be shared. Original examle is little hacish so I dont want to use that as example.
kalle_h
 
Posts: 636
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby Overflow_se » Wed Feb 08, 2012 9:44 pm

Thanks for this Kalle! I tried it in my current libgdx project and it works well. I looked through the code but I have not worked with gles 2.0 or shaders before so I appologize if this question is stupid. Is it possible to not apply the shaders to the "background" layer(s) I.e. I use bloom.capture() and it seem to record all rendering done from that point until I do bloom.render(). If I draw the background before capture() it does not show at all due to the glclear command inside bloom.capture(). excluding layers "above" from the bloom effect was no problems tho, just render normal after bloom.render().
Android Space Shooter http://www.aperico.com/stardust
Overflow_se
 
Posts: 76
Joined: Wed Oct 12, 2011 1:32 pm

Re: Bloom lib.

Postby Overflow_se » Wed Feb 08, 2012 11:01 pm

I get this error when deploying to device tho :(

Code: Select all
02-08 23:57:27.995: E/AndroidRuntime(5129): FATAL EXCEPTION: GLThread 10
02-08 23:57:27.995: E/AndroidRuntime(5129): com.badlogic.gdx.utils.GdxRuntimeException: Texture width and height must be powers of two: 480x800
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.uploadImageData(Texture.java:196)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.load(Texture.java:179)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:154)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:150)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.glutils.FrameBuffer.build(FrameBuffer.java:96)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.glutils.FrameBuffer.<init>(FrameBuffer.java:90)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.bloom.Bloom.initialize(Bloom.java:158)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.bloom.Bloom.<init>(Bloom.java:81)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.game.starscream.screens.WorldScreen.<init>(WorldScreen.java:110)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.game.starscream.StarScream.createGame(StarScream.java:121)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.game.starscream.screens.SplashScreen.render(SplashScreen.java:36)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.Game.render(Game.java:46)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:423)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1388)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)


Looks like the libgdx FrameBuffer does not like anything but powers of 2? Strange it works well on desktop..
Android Space Shooter http://www.aperico.com/stardust
Overflow_se
 
Posts: 76
Joined: Wed Oct 12, 2011 1:32 pm

Re: Bloom lib.

Postby kalle_h » Wed Feb 08, 2012 11:15 pm

Overflow_se wrote:Thanks for this Kalle! I tried it in my current libgdx project and it works well. I looked through the code but I have not worked with gles 2.0 or shaders before so I appologize if this question is stupid. Is it possible to not apply the shaders to the "background" layer(s) I.e. I use bloom.capture() and it seem to record all rendering done from that point until I do bloom.render(). If I draw the background before capture() it does not show at all due to the glclear command inside bloom.capture(). excluding layers "above" from the bloom effect was no problems tho, just render normal after bloom.render().


For background exclude you need enable blending.

Use this constructor:
Code: Select all
public Bloom(int FBO_W, int FBO_H, boolean hasDepth, boolean useBlending,
         boolean use32bitFBO) {

Don't worry about glClear that only affect to current fbo to bound.

When blending is enabled render background first and start capturing and render when finished. There is also capturePause and captureContinue if needed.
kalle_h
 
Posts: 636
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby kalle_h » Wed Feb 08, 2012 11:19 pm

Overflow_se wrote:I get this error when deploying to device tho :(

Code: Select all
02-08 23:57:27.995: E/AndroidRuntime(5129): FATAL EXCEPTION: GLThread 10
02-08 23:57:27.995: E/AndroidRuntime(5129): com.badlogic.gdx.utils.GdxRuntimeException: Texture width and height must be powers of two: 480x800
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.uploadImageData(Texture.java:196)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.load(Texture.java:179)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:154)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:150)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.glutils.FrameBuffer.build(FrameBuffer.java:96)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.graphics.glutils.FrameBuffer.<init>(FrameBuffer.java:90)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.bloom.Bloom.initialize(Bloom.java:158)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.bloom.Bloom.<init>(Bloom.java:81)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.game.starscream.screens.WorldScreen.<init>(WorldScreen.java:110)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.game.starscream.StarScream.createGame(StarScream.java:121)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.aperico.game.starscream.screens.SplashScreen.render(SplashScreen.java:36)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.Game.render(Game.java:46)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:423)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1388)
02-08 23:57:27.995: E/AndroidRuntime(5129):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)


Looks like the libgdx FrameBuffer does not like anything but powers of 2? Strange it works well on desktop..


That sound odd. You can solve it by sending your own fbo in constructor parameter.
Code: Select all
   public Bloom(int FBO_W, int FBO_H, FrameBuffer sceneIsCapturedHere,
         boolean useBlending, boolean use32bitFBO) {


And send

Code: Select all
      frameBuffer = new FrameBuffer(Format.RGBA8888,512,512,false);

If its look blurry you can try 1024x512.
kalle_h
 
Posts: 636
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby mzechner » Thu Feb 09, 2012 3:29 am

Overflow_se, enable GLES 2.0 by passing the correct parameters to the AndroidApplication#initialize method. If your phone doesn't support GLES 2.0, libgdx will fall back to 1.x, which will result in the error you see.
mzechner
Site Admin
 
Posts: 4715
Joined: Sat Jul 10, 2010 3:50 pm

Re: Bloom lib.

Postby Sippolo » Thu Feb 09, 2012 9:04 am

kalle_h wrote:Sippolo: Finally fixed the bug. It was pain to found. Source was inside of SpriteBatch. SpriteBatch allways bind to current texture unit but use texture unit 0. I did solved this by making sure that last texture unit used inside of bloom is 0.


Very nice kalle_h!
It works like a charm now, thanks :)
Sippolo
 
Posts: 67
Joined: Thu Jan 12, 2012 12:19 pm
Location: Italy

PreviousNext

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest