Author Topic: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae  (Read 8197 times)

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Hi,
     I am trying to experiment with MultiPass Rendering with jpct ae . I was trying to do 2 pass Gaussian blur . I was able to get individual blurs Successfully , i.e horizontal and vertical blurs individually . But what I want is ->
1) Render the "Bright" part to a texture.
1) the output from the 1st step should undergo horizontal blurring .
2) the output from the 2nd step should undergo vertical blurring
3) The output from the 3rd step would be blended in some way with the original rendered image for the post processing bloom effect .

   So how do we do multipass rendering in jpct ae ? And pass the result from one render phase to the other for further processing? Also I have to composite the processed Bloom with the final image .
I just know the theory for now..... a pointer to actual implementation would help a lot .  :)
Thanks in advance. :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #1 on: April 30, 2017, 10:30:58 am »
Just use some additional render targets?

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #2 on: April 30, 2017, 11:57:12 am »
   I tried something like this->
Code: [Select]
                        fb.setRenderTarget(target1);

fb.setBlittingShader(shader1);
fb.clear(new RGBColor(123, 223, 237));
world.renderScene(fb);
world.draw(fb);
fb.display();


fb.setRenderTarget(target2);
fb.setBlittingShader(shader2);
fb.clear(new RGBColor(123, 223, 237));
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.blit(target2, 0, 0, 0, fb.getHeight(), target1.getWidth(), target1.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);



But this only shows me the output of second pass , ignoring the first one .
Am i missing something or do I have to remove something ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Where the relation between target1 and target2 in that code? You render into target1, then into target2 and then you blit target2. I don't see where target1 is actually used here!?

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Yes ... this code is not correct :(
there is something missing ...
But that's what my question is .... How to set this relation between target1 and target2 .
What is happening actually is , the target1 is having the vertical blurring . Now  this target1 texture has to be fed to the input of second pass....
So that the already vertically blurred image can be processed again with horizontal blur . You mentioned that this can be achieved with 2 render targets .So for now  I have created 2 render Targets... but then I was blank....I am not sure how to do this part in jpct ae.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
How is the general idea? You render the scene into target1, which includes the first blur. Then you want to use the same texture (target1) as the source for the other blur step and blit the resulting image?

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Yes exactly!
At least this is what should happen according to my understanding... in theory,
So Yes I need to know jpct ae steps to execute the same idea .
Is this realizable this way ?
 Or....
If you have some alternate feasible / better way, please suggest. :)

Cause I would be then using this idea further for Post processing blur , So i guess I would have to do a third pass as well, for combining the blurred bright texture with the normal rendered image texture...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
I would try something like this:

  • set target1, render the scene
  • set target2, set the second blur shader as blitting shader and blit target1 fullscreen into target2
  • remove the render target and blit target2 to the screen

In your code, you render the scene twice and I'm not sure if that's needed here. If target2's size isn't the same size as the screen, you might have to adjust the blitting coordinates. Here's some basic example that shows this: http://www.jpct.net/forum2/index.php/topic,4609.msg31858.html#msg31858

Another approach is to use an Overlay instead of blit(). You can obtain the Object3D from an overlay and assign your own shader to that one (just like you would with setBlittingShader()). That method has to no need to convert the coordinates.

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Hi Egon,

You said
Quote
blit target1 fullscreen into target2
.
I got confused with this...did you mean that I should simply use fb.blit() ?? just after setting rendering to target 2 with blurring ?
like this->
Code: [Select]
// the first step you mentioned
                        fb.setRenderTarget(target1);
fb.setBlittingShader(shader1);
fb.clear(new RGBColor(123, 223, 237));
world.renderScene(fb);
world.draw(fb);
fb.display();
//the 2nd step->
fb.setRenderTarget(target2);
fb.setBlittingShader(shader2);
fb.blit(target1, 0, 0, 0, fb.getHeight(), target1.getWidth(), target1.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);   // this ? I'm not sure...

// the 3rd step->
fb.removeRenderTarget();
fb.blit(target2, 0, 0, 0, fb.getHeight(), target1.getWidth(), target1.getHeight() , fb.getWidth(), -fb.getHeight(), -1, false);


this did not worked... so this must be wrong, I know ...
But I'm asking this... because I failed to find any method which allows me to blit a texture to another in fullscreen...

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Is using an shader for an Overlay-Object3D here better than using a blitshader?
I think effectively you can reach the same goals..? But what would be faster here?
« Last Edit: May 03, 2017, 01:23:01 am by AeroShark333 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #10 on: May 03, 2017, 08:59:45 am »
You said
Quote
blit target1 fullscreen into target2
.
I got confused with this...did you mean that I should simply use fb.blit() ?? just after setting rendering to target 2 with blurring ?
Yes, that's what I meant. In which way does it not work?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #11 on: May 03, 2017, 09:01:06 am »
Is using an shader for an Overlay-Object3D here better than using a blitshader?
I think effectively you can reach the same goals..? But what would be faster here?
It shouldn't really matter. Which one is better is merely a matter of taste. Blitting into render targets can require some coordinate adjustments, so using an Overlay might be more intuitive for some though.

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #12 on: May 03, 2017, 01:06:29 pm »
Is using an shader for an Overlay-Object3D here better than using a blitshader?
I think effectively you can reach the same goals..? But what would be faster here?
It shouldn't really matter. Which one is better is merely a matter of taste. Blitting into render targets can require some coordinate adjustments, so using an Overlay might be more intuitive for some though.
And performance-wise?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #13 on: May 03, 2017, 01:18:06 pm »
It depends. I would say it's like the difference between starting a marathon with your left or with your right leg...

Offline SonicBurst2

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Gaussian Blur |Post Processing Bloom| MultiPass Rendering in jpct ae
« Reply #14 on: May 03, 2017, 09:04:57 pm »
Quote
In which way does it not work?
It displays some weird artifacts like this (please see attachment)

and after few seconds , it crashes due to out of memory exception... :(

The Code is the same , the earlier posted code....
« Last Edit: May 03, 2017, 09:09:12 pm by SonicBurst2 »