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: 460
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
yeah well that's a sig
syl
 
Posts: 195
Joined: Mon Nov 01, 2010 10:25 pm

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: 460
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: 98
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: 460
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: 460
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: 460
Joined: Thu Dec 29, 2011 9:50 pm

Previous

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest

x