Bloom effect problem.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Andrey01
Posts: 57
Joined: Mon Jul 27, 2020 9:08 pm

Bloom effect problem.

Post by Andrey01 »

I've implemented a bloom effect shader together with the phong lighting. My problem is two white light sources which the bloom is applied for have a mild purple tint at the edges:
Image

Shortly, how I implement bloom in code:
1. Add four materials types using 'addHighLevelShaderMaterialFromFiles()'. The first "lighting_mat" is used for rendering all scene with the yellow sphere which is affected by the phong lighting. The second "bfe_mat" is used to render those two lights with just a white color. In third "blur_mat" the gaussian blurring is executed. And four "final_mat" is used for rendering the total scene.
2. Render the sphere and camera scene nodes and then two lights meshes (without bloom) into the "BaseLightRT".
3. Blur the obtained image in the cycle using ping-pong technique: render alternately in the "BlurRT" and "BlurRT2" textures using the previous result blurring them horizontally and vertically.
4. Combine "BaseLightRT" and "BlurRT".

My guess is while blurring in the fragment shader it takes surrounding pixels colors from the background (which is blue color) of the mBrightTex and mix them with the current kernel. However, it is strange since I render to that texture skybox with wooden textures, so its pixels should be taken into account.

Still one weird thing that I discovered is 'setRenderTargetEx()' always sets a blue color as the clear one disregarding passed clearColor param (in my case is black).

My source:
https://drive.google.com/file/d/1PYIUqe ... sp=sharing
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Bloom effect problem.

Post by CuteAlien »

SColor is a,r,g,b (unlike SColorf which is r,g,b,a - historical reasons which are no longer fixable without breaking everyones code). So you do actually pass blue ;-)

For the other thing I need to find a bit time to investigate, code getting a bit too large for me to see it quickly. Thought you might want to experiment with different E_TEXTURE_CLAMP in your material layers (TextureWrapU, TextureWrapV). At least that would be my first guess.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Bloom effect problem.

Post by CuteAlien »

Basically - you do not render the sphere when you do blurring. You only render cubes there before the blue (see last post) background.
There's a simple trick to see the result of your intermediate steps in your app. Before endScene() add something like:

Code: Select all

            core::dimension2du preview_size(wnd_size.Width/4, wnd_size.Height/4);
            vdrv->draw2DImage(blur_imgs[0], core::recti( 0, 0, preview_size.Width, preview_size.Height),
							core::recti(0,0,wnd_size.Width, wnd_size.Height));
Now you see a tiny version of that image.

edit: Btw, I'm not too familiar with bloom, would have to read up first how that is usually done. But in case that need some full-screen effect you may want to check out the new example 27.PostProcessing in Irrlicht svn trunk. That one is about doing full-screen effects. Possibly you need that + some mask (so you don't have to re-render the whole scene x times which is super expensive).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Andrey01
Posts: 57
Joined: Mon Jul 27, 2020 9:08 pm

Re: Bloom effect problem.

Post by Andrey01 »

Thanks for help. I decided to follow a bit other implementation of bloom that used the screen quads: viewtopic.php?t=51017&hilit=bloom . That fixed my issue and made the lights much more blurred.

For comparison:

Without screen quads
Image

With screen quads
Image
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Bloom effect problem.

Post by CuteAlien »

Nice. And yeah - that example 27 was also about screen quads.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply