Page 1 of 2

Glow OpenGL shader ... NOOB!

Posted: Wed Aug 31, 2011 4:23 pm
by Auradrummer
Hello guys,

I'm trying to work with shaders and made some good progress, making glass and another tratments here. Fine!

Now, I want to give one more step, and working with glow or blur effects, within shaders.

Studying around, I think I understood the steps to make a glow shader. Correct me if I misunderstood:
1. Create a new framebuffer;
2. Render the glowing parts in this framebuffer;
3. Blur them (gaussian);
4. Proceed with the rendering normally;
5. SUM that "new" framebuffer to the current framebuffer;
6. Let's go to the screen.

So, first of all, I need to learn how to create a new FBO (Frame Buffer Object).
I saw that I have to use this void function:
glGenFramebuffersEXT(x,y);

But, seems that I cannot call this function inside the Irrlicht fragment shader.
How can I create a new framebuffer using shaders inside Irrlicht?

Thanks, and don't forget, I'm newbie :D

Re: Glow OpenGL shader ... NOOB!

Posted: Wed Aug 31, 2011 4:53 pm
by Lonesome Ducky
The method used with irrlicht is to create a render texture, render the glowing objects to that, then later pass that as a parameter to another shader to sum them.

Re: Glow OpenGL shader ... NOOB!

Posted: Fri Sep 02, 2011 2:08 pm
by Auradrummer
Ah ... good, I made this with another shader, so is the correct manner.

But, now I have to proceed with the next step. How apply an image treatment.
Imagine that I have to make an Infra Red view. I think that changing the material of everything in the world isn't the best way.
So, how can I apply a shader in the final rendering result?

Thanks guys.

Re: Glow OpenGL shader ... NOOB!

Posted: Fri Sep 02, 2011 3:41 pm
by shadowslair
There`re plenty of postprocess shader examples around, why don`t you simply take one and check the code? :|
Of course you`ll need to modify the shaders a bit, but the project on Irrlicht side will be ready for you.

Re: Glow OpenGL shader ... NOOB!

Posted: Sat Sep 03, 2011 10:40 pm
by Auradrummer
Hi Shadowslair,

So, this is called postprocess? I really found some nice postprocessing examples, but I was not pretty sure that is the thing. Now I have a path to go.
Thanks for the answer, let's work!

Re: Glow OpenGL shader ... NOOB!

Posted: Sat Mar 01, 2014 11:50 am
by motorfreak
No you render your world as normal but to two different buffers at the same time. One will contain all "glow" materials. The other will contain all normal stuff. Then you render a single quad that covers the whole screen with a shader to which you pass the two framebuffers that you have created in the previous pass. It is this shader that samples both textures such that you get the blur, glow, night vision etc. effect.

Re: Glow OpenGL shader ... NOOB!

Posted: Mon Mar 03, 2014 1:47 am
by papaonn
Support this,

Mind helping us as newbies by providing a beginning sample code of how to apply render to texture as multi shading?
Sorry, I tried searching over many posts but most of them are too old and the links are broken.

We only need really simple sample code, for the good of the rest like us as well.
Much appreciated.
Thanks =)

Re: Glow OpenGL shader ... NOOB!

Posted: Wed Mar 05, 2014 8:15 am
by papaonn
please ;'(

Re: Glow OpenGL shader ... NOOB!

Posted: Thu Mar 06, 2014 1:32 am
by mongoose7
Some examples of postprocessing were posted here about two or three years ago. Try googling this site.

Re: Glow OpenGL shader ... NOOB!

Posted: Thu Mar 06, 2014 9:50 am
by papaonn
I tried for weeks now TnT but the source files had been removed TnT
please provide us newbie a guide TnT

Re: Glow OpenGL shader ... NOOB!

Posted: Fri Mar 07, 2014 12:30 am
by mongoose7
It works like photoshop. You render to a render target texture. Then reset the render target to the framebuffer. The texture is now available to use as a texture, so use it to texture a quadrilateral with a shader. The shader can simply write the texture colour, or it can change it somehow. For example, by reading the texture values around the (u, v) point and averaging them, you can blur the scene. Above you have been told that glow needs two textures, but you can achieve a rudimentary glow by reading the texture and, if the colour is 'bright', increase it even more. Also, if the colour is not so bright, sample the texture around the point and if there are any bright points nearby, increase the intensity inversely proportional to the distance.

But you can do whatever photoshop filters do. For example, by also reading another texture, say a grid, you can multiply the two textures to have the grid appear over the scene.

Re: Glow OpenGL shader ... NOOB!

Posted: Fri Mar 07, 2014 3:46 pm
by papaonn
thanks bro, I am well known to graphics theory, the only problem I had is that I wonder why my code isn't working, so would like to have a simple example of how to use it properly. :(

Re: Glow OpenGL shader ... NOOB!

Posted: Sat Mar 08, 2014 3:38 am
by The_Glitch
You might should post your code as no one is most likely to post there's. I believe with Irrlicht it's actually easier to do a glow shader then most other engines. I remember seeing a example of one on the forums and the shader was about 12 lines mostly whitespaces. The hardest part is most likely just the rtt. Let me know if you would like to see it.

Re: Glow OpenGL shader ... NOOB!

Posted: Mon Mar 10, 2014 9:45 am
by papaonn
This is where i setup 2 textures (2 shaders) :

Code: Select all

ITexture * rtt0 = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(256,256), "RTT0");
body->getMaterial(0).setTexture(0, rtt0);
 
ITexture * rtt1 = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(256,256), "RTT1");
body->getMaterial(0).setTexture(1, rtt1);

This is where i started to integrate 2 shaders into 1 scene node, but failed. :(

Code: Select all

 
// set render target texture
node->setVisible(false);
 
videoDriver->setRenderTarget(rtt0, true, true, video::SColor(0,0,0,0));
node->getMaterial(0).MaterialType = (E_MATERIAL_TYPE) gShaderA;
node->render();     
 
videoDriver->setRenderTarget(rtt1, false, false, video::SColor(0,0,0,0));
node->getMaterial(0).MaterialType = (E_MATERIAL_TYPE) gShaderB;
node->render();
 
// draw whole scene into render buffer
sceneManager->drawAll();
 
// set back old render target
// The buffer might have been distorted, so clear it
videoDriver->setRenderTarget(0, true, true, video::SColor(0, 0, 0, 0));
 
node->setVisible(true);
sceneManager->drawAll();
 

Re: Glow OpenGL shader ... NOOB!

Posted: Tue Mar 11, 2014 10:26 am
by The_Glitch
I can't say for sure but I did a quick glance and I know Irrlicht doesn't like a single node to have 2 shaders applied. Is your effect all in one shader or is it 2 separate shaders?