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 » Fri Feb 24, 2012 10:56 pm

syl wrote:thanks for your contrib :D
is it tested with decalbatch ? i'm having an issue : blackscreen after a very short time when i see something. i tried different settings from the simple new Bloom(); to bloom = new Bloom(1024, 1024, true, true, true);

here is my screen code (it's just a simple test, based on decaltest)
Code: Select all
package com.syl.test;

import java.util.LinkedList;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.decals.Decal;
import com.badlogic.gdx.graphics.g3d.decals.DecalBatch;
import com.badlogic.gdx.graphics.g3d.decals.GroupStrategy;
import com.badlogic.gdx.graphics.g3d.decals.SimpleOrthoGroupStrategy;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;

public class SplashScreen implements Screen {

   private Bloom bloom;
   
   public static final int TARGET_FPS = 40;
   public static final int INITIAL_RENDERED = 100;
   private boolean blending = true;
   private GroupStrategy strategy = new GL20GroupStrategy();
   //private GroupStrategy strategy = new SimpleOrthoGroupStrategy();
   // private GroupStrategy strategy = new DefaultGroupStrategy();
   Texture egg;
   Texture wheel;
   LinkedList<Decal> toRender = new LinkedList<Decal>();
   DecalBatch batch;
   Camera cam;
   int idx = 0;

   float wait = 30;


   private Game test;


   /**
    * Constructor for the splash screen
    * @param g Game which called this splash screen.
    */
   public SplashScreen(Game g) {
      test = g;
   }

   @Override public void render(float delta) {

      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
      
      for (Decal decal : toRender) {
         decal.rotateZ(delta * 45);
         batch.add(decal);
      }
      
      bloom.capture();

      batch.flush();
      
      bloom.render();

      wait -= delta;
      if (wait < 0 || Gdx.input.justTouched()) {
         test.setScreen(new MenuScreen(test));
      }
   }

   @Override public void resize(int width, int height) {
      cam = new OrthographicCamera(width, height);
      cam.near = 0.1f;
      cam.far = 10f;
      cam.position.set(0, 0, 0.1f);
      cam.direction.set(0, 0, -1f);
      cam.update();
      if (Gdx.graphics.isGL20Available()) {
         ShaderProgram shader = strategy.getGroupShader(0);
         shader.begin();
         shader.setUniformMatrix("u_projectionViewMatrix", cam.combined);
         shader.setUniformi("u_texture", 0);
      } else {
         cam.apply((GL10)Gdx.gl);
      }
   }

   @Override public void show() {

      //bloom = new Bloom(); //too small can cause aliasing but is lot faster
      bloom = new Bloom(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 4, false, false, true);
      //bloom = new Bloom(1024, 1024, true, true, true);
      
      Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
      Gdx.gl20.glDepthFunc(GL20.GL_LESS);

      egg = new Texture(Gdx.files.internal("egg.png"));
      egg.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
      egg.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);

      Decal egg_sprite = Decal.newDecal(new TextureRegion(egg), blending);
      egg_sprite.setPosition(0, 256, -1);
      toRender.add(egg_sprite);

      wheel = new Texture(Gdx.files.internal("wheel.png"));
      wheel.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
      wheel.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);

      Decal wheel_sprite = Decal.newDecal(new TextureRegion(wheel), blending);
      wheel_sprite.setPosition(256, 0, -2);
      toRender.add(wheel_sprite);

      batch = new DecalBatch(strategy);

      Gdx.gl.glClearColor(1, 1, 0, 1);
   }

   @Override public void hide() {
   }

   @Override public void pause() {
   }

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

   @Override public void dispose() {
   }
}



I'm using this GL20GroupStrategy viewtopic.php?f=11&t=2732&p=13977&hilit=GL20GroupStrategy#p13994

is it a problem or a conflict ?

Thanks :)


I don't know how those decals work but I would suggest you to start with minimal test case. If that does not work then its lot simpler to find problem. Usually black screen with openGl is just some openGL state that leaked and really hard to spot.
kalle_h
 
Posts: 640
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby syl » Sat Feb 25, 2012 1:17 pm

it works with CameraGroupStrategy :roll:

will this work go to libgdx SVN ? i've seen that you have a lights package as wip
syl
 
Posts: 212
Joined: Mon Nov 01, 2010 10:25 pm
Location: Bordeaux, France

Re: Bloom lib.

Postby kalle_h » Sat Feb 25, 2012 1:57 pm

syl wrote:it works with CameraGroupStrategy :roll:

will this work go to libgdx SVN ? i've seen that you have a lights package as wip


I think something like this is too spesific for the trunk. But something like postprocessor API would be handy at somepoint but I am not right person to answer this.
kalle_h
 
Posts: 640
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby dud3z » Wed Feb 29, 2012 12:48 pm

@kalle: in the setTreshold function you also set the reciprocal value of "treshold" as "tresholdD", in order to scale back the color to preserve full range, but shouldn't it be the reciprocal of "1-treshold" instead? I think the line should then read:

Code: Select all
tresholdShader.setUniformf("tresholdD", (1f / (1-treshold)));
dud3z
 
Posts: 123
Joined: Wed Jan 04, 2012 1:10 pm

Re: Bloom lib.

Postby kalle_h » Wed Feb 29, 2012 8:16 pm

dud3z wrote:@kalle: in the setTreshold function you also set the reciprocal value of "treshold" as "tresholdD", in order to scale back the color to preserve full range, but shouldn't it be the reciprocal of "1-treshold" instead? I think the line should then read:

Code: Select all
tresholdShader.setUniformf("tresholdD", (1f / (1-treshold)));


That work too and that would be right way to do treshold. But in my testes 1f/treshold look better. Library is freely modied to users need and if you want more than one post process effects those all should be combined to one anyway and that would need mofications.
kalle_h
 
Posts: 640
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby kalle_h » Thu Mar 29, 2012 9:32 pm

I create google-code project http://code.google.com/p/bloom-lib/

Also I fiddled with treshold and its use now dud3z correction. Default values are bit different now but the output should be about same. Also massive optimization have be done. If any color quality problems will occur report me immediatly.
kalle_h
 
Posts: 640
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby kalle_h » Fri Mar 30, 2012 2:03 pm

Should be about twice as fast with poverVR devices. Can anyone confirm that?
kalle_h
 
Posts: 640
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby Lomelin » Tue Aug 20, 2013 6:18 pm

kalle_h wrote:
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.


I'm sorry to dig it up but I'm using your lib for quite a while now and I'd like to do some changes : for the moment the whole scene is bloomed but I'd like to apply the effect only on the fireballs.
I'd tried this :

Code: Select all
bloom = new Bloom(512, 512, true, true, true);
// @ render
batch.begin();
batch.draw(ships)
bloom.capture();
batch.end();
bloom.render();


But the whole scene is still affected. I've tried stopping the batch before bloom.capture() and starting it again : It kinda works, only my bullets bloomed but I only see my bullets.. :/

Am I doing something wrong ?

Thanks for your time !
Lomelin
 
Posts: 214
Joined: Fri Feb 24, 2012 4:58 pm
Location: Belgium

Re: Bloom lib.

Postby Lomelin » Fri Aug 30, 2013 7:32 am

Up up up :)
Lomelin
 
Posts: 214
Joined: Fri Feb 24, 2012 4:58 pm
Location: Belgium

Re: Bloom lib.

Postby Lomelin » Sat Aug 31, 2013 6:33 am

I've tried again and I can get only one part of the render affected by the bloom but that's the second part.. by doing another batch.being() batch.end().
But that's not very useful in my case because I want the bullets to be affected by the bloom and I also want them to be on top of everything.. :/
Lomelin
 
Posts: 214
Joined: Fri Feb 24, 2012 4:58 pm
Location: Belgium

PreviousNext

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 3 guests