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 mzechner » Sun Jan 22, 2012 9:20 pm

we should totally put your contributions in our extensions and have them build with our stuff :D
mzechner
Site Admin
 
Posts: 4715
Joined: Sat Jul 10, 2010 3:50 pm

Re: Bloom lib.

Postby kalle_h » Sun Jan 22, 2012 11:55 pm

mzechner wrote:we should totally put your contributions in our extensions and have them build with our stuff :D

I am glad to hear this.
kalle_h
 
Posts: 637
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby berserker.devel » Mon Jan 23, 2012 10:34 am

Great work!
I'm trying to play a little with this but as far as I understand this is supposed to work with the "entire scene" right?
Would it be possibile to use the bloom only for specific objects in the scene?
I mean something like:
  • Render the background (no bloom)
  • Render some shapes (bloom enabled)
  • Render the UI (no bloom)
berserker.devel
 
Posts: 40
Joined: Tue Aug 30, 2011 3:25 pm

Re: Bloom lib.

Postby kalle_h » Mon Jan 23, 2012 5:09 pm

UI part is allready possible.

I can add alpha channel to fbo via cosntructor parameter: useBlending.
Maybe I need to add stop capture also.
kalle_h
 
Posts: 637
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby kalle_h » Mon Jan 23, 2012 7:13 pm

Updated.

Added constuctor parameter useBlending. This will add alpha channel to fbo and
Added methods:
-CapturePause
-CaptureContinue
-setClearColor(with this glow over bloomed objects when using blending can be colored)


Background is rendered normally. Cube in front is using tranparent material. This make cube show as almoust transparent but when reflective light meet the view direction stealth object is clearly visible.
Image
Last edited by kalle_h on Thu Mar 29, 2012 9:33 pm, edited 1 time in total.
kalle_h
 
Posts: 637
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby kalle_h » Mon Jan 23, 2012 7:19 pm

One note: blooming is screen space effect so don't try to optimize blooming by using blending. That just make things even worse.
kalle_h
 
Posts: 637
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby kalle_h » Mon Jan 23, 2012 7:42 pm

Added consructor parameter use32bitFBO. If false FBO is rgb656 or rgba4444 depending on blending and if true FBO is rgb888 or rgba8888.
kalle_h
 
Posts: 637
Joined: Thu Dec 29, 2011 9:50 pm

Re: Bloom lib.

Postby berserker.devel » Tue Jan 24, 2012 9:02 am

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

Added constuctor parameter useBlending. This will add alpha channel to fbo and
Added methods:
-CapturePause
-CaptureContinue
-setClearColor(with this glow over bloomed objects when using blending can be colored)

You are my hero :D :D :D

Before:
Image

After:
Image

Thanks!
berserker.devel
 
Posts: 40
Joined: Tue Aug 30, 2011 3:25 pm

Re: Bloom lib.

Postby berserker.devel » Tue Jan 24, 2012 9:34 am

I just tested this on a Galaxy Nexus and it has a huge impact on the frame rate :( (from 60 to ~21 fps with default params).
In my previous screenshot all the shapes are a single Mesh object: do you think it would be possible to get rid of the FBO and "embed" the Bloom code into my existing shader? Should it increase the frame rate?

Actually my shader is very simple:

- Vertex
Code: Select all
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoords;
varying vec4 v_color;
varying vec2 v_texCoords;
uniform mat4 u_scene_matrix;

void main()
{
   v_color = a_color;
   v_texCoords = a_texCoords;
   gl_Position = u_scene_matrix * a_position;   
}

- Fragment
Code: Select all
#ifdef GL_ES
   precision mediump float;
#endif

varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform float u_scene_alpha;

void main()
{
   gl_FragColor = v_color * texture2D(u_texture, v_texCoords);   
   gl_FragColor.a = gl_FragColor.a * u_scene_alpha;
}
berserker.devel
 
Posts: 40
Joined: Tue Aug 30, 2011 3:25 pm

Re: Bloom lib.

Postby kalle_h » Tue Jan 24, 2012 4:03 pm

You have choise to use smaller fbo where you capture the scene. This is expert usage and not yet fully tested. So you have give FrameBuffer object as paramter. Try size that about 75% of width and 75% of height. That lower fillrate and you gain lots of fps but the end image get little blurry but that might not be problem at all with bloom effect. If that raise fps to over 30 then you its should be enough for smooth gameplay.
Also you might want only use blooming when something special is happening. Powers up, near death or something. Then effect dont wear old so fast.
kalle_h
 
Posts: 637
Joined: Thu Dec 29, 2011 9:50 pm

PreviousNext

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 0 guests