Better Bloom Filter w/ Down Sampling & Lens Flares

We all know bloom is a filter that makes some area/objects looks more glowy, and BGE already got that, but here comes some problem:

  • The bloom filter on BGE sometimes blooms objects/areas where do we dont want
  • Really FPS consumtive

So I thought why not make a better bloom filter? :yes:

  • Less FPS consumtive
  • Selective Bloom


  • Some artifacts on non-bloom objects
  • I don’t know why but its 1 frame behind… bge.logic.NextFrame() doesn’t work

Download v1.0
BetterBloomFilter.blend (792 KB)
Download v1.1
BetterBloomFilter.blend (809 KB)

Download v2.0 - Added lens flares
BetterBloomFilter.blend (783 KB)
Download v2.2 - Invisible objects glitch fix

Would like to hear your thoughts :slight_smile:

This is cool!
The 1 frame behind bug is really bad. We might fix this in UPBGE.

can you use a predraw callback?

sorry I’ve never heard of this, can you please explain with examples?


I use it for weapons on actors using copy rotation constraints, since the constraint step is after the logic step*

you just define a function, and then stick it in as a callback,

nextFrame only works from when python is the scene script. There are no examples and is no documentation on this, but if you create a scene property “main” and make it’s value a python script, the script will be executed upon game start, then nextFrame() will work.

I recall trying to put renderToTexture into a predraw callback without success. Or maybe that was ImageMirror(). Give it a try:

def funct_to_run():
    print("Running just before drawing, after physics and motion etc.")


Be aware that accessing objects may do weird things. Interacting with sensors and actuators (Eg trying to set parameters) will fail. There is no bge.logic.getCurrentController() and a few other funny things.

I would be interested in a direct comparison between a down-sampled render-to-texture bloom and a full resolution 2D filter bloom. I suspect the 2D filter would win by virtue of not needing to render the scene twice. But then I suppose O(n) (number of pixels drawn using RTT) vs O(n^2) (number of pixels processed in 2D filter) says that the render-to-texture may be slightly faster, so long as the overhead isn’t too great.

Update v2.0 - Added lens flares & some chromatic aberrations

Nice work kitebizelt! and thanks for sharing :slight_smile:

My suggestion:
Use 2-step blur. Why? Because it is faster.
Current blur method is:

for i in samples:
    for j in samples:
        calculate vertical = i;
        calculate horizontal = j;

This way you end up with i*j calculations per fragment. For case of bloomSIze set to 4 it’s 16. That’s not a problem. However, if you set the bloomSize to 16, for example, it starts to lag a lot. And it has a reason, for sure. 16x16 = 256 calculations.
The 2 step method, however, is better for the 16 case.
It first calculates the blur horizontally and stores the result in new texture. After that it blurs vertically.
So in case of 2x2 or 3x3 blur it’s not as effective as it takes 4(or 6) samples instead of 4(or 9)(which can be a slight improvement), but requires additional texture which will end up being less effecient. In case of 5x5 or more samples, however, the boost can be noticeable. In case of 8x8, for example, it’s 16 samples instead of 64(4x better) and the additional texture uses just a little bit of additional resources. Overally in this case the improvement is approximately 3x. But in more sample cases it’s growing exponentionally(e.g. in 16x16 case it’s 32 instead of 256 and thus 8 times more efficient - such a big improvement). I suggest you to look into this method.
It’d also be cool if you added bloom strength parameter.

By the way - the bloom by itself is not working for me in your .blends. Only flares and chromatic aberation, but not bloom.

This is amazing just what i need. However, there is a few problems i have come across.
I will just go with the one that i need to get over, to use it :slight_smile:

Object that have Visibility turned off, now are visible. This is a big problem for me as i
have my object box for my player and other effects.

In script add test for a certain property that you add to objects that you want to be invisible and if the object has the specific property, than don’t do obj.visible = True.

How do i do that. My scripting skills = 0

that’s strange… Try running in standalone mode and see if it gives you an error
and also thanks for the suggestion :slight_smile:

Update v2.2 fixed the glitch on invisible object
Before running besure to add ‘invisible’ property to invisible objects, and then set the value to 1

It works well in standalone, but doesn’t work in embed. Interesting…

By the way - try making this a selective bloom of certain range. If we had HDR in BGE, we could make it really high-definition, but… All what we got, we must use;)

TwisterGE posted this a while ago. I guess its close to HDR:

Regarding the filter: Is there anyway you could draw circles of bloom instead of just up/down + left/right?

Using gaussian blur, I guess;) Some constant arrays can be used.

Thank you kitebizelt for the fix, works amazing.
In my game i change cameras to aim, what happens then is the Filter don`t work
properly, because i changed camera. Is there a work around for this ?

I like this filter, please keep working on it :slight_smile: