* * *

Author Topic: Fast hardware image blur  (Read 9604 times)

circular

  • Hero Member
  • *****
  • Posts: 2570
    • Personal webpage
Re: Fast hardware image blur
« Reply #60 on: March 12, 2017, 07:12:19 pm »
Yep
Conscience is the debugger of the mind

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #61 on: March 13, 2017, 07:43:39 am »
Thanks you both for all this.

@Circular, you will include a blur demo in bgrabitmap or maybe somewhere in another repository?

You are very welcome
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #62 on: March 13, 2017, 07:49:50 am »
@simin_sh: What I am suggesting is to use weight = 1/(2*range+1)

That would give a box blur as a result.

Otherwise you can try to create the framebuffers only once, or recreate them only if the size has changed. And free them when the form is closed.

About the time begin 0 or 15 ms, that's normal because the grain of time is equal to 15 ms. To have more precision, you could use EpikTimer, or do the same thing 10 times and then divide the time by 10.

Thank you for your replay

I tested the formula for Box Blur, it seems that the time does not have that much different, but as you said when I calculate the average time for 30 Blur with different sigma, time is 3-5 ms for each one, I think it is okay for now, but I still need to save it in the end, and check the time I need.

Regards
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

circular

  • Hero Member
  • *****
  • Posts: 2570
    • Personal webpage
Re: Fast hardware image blur
« Reply #63 on: March 13, 2017, 07:36:54 pm »
I've added BGLCanvas.GetImage. It returns a TBGRABitmap object that you can save.
Conscience is the debugger of the mind

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #64 on: March 14, 2017, 08:53:39 am »
I've added BGLCanvas.GetImage. It returns a TBGRABitmap object that you can save.


Thank so much Circular.
Regards
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #65 on: March 15, 2017, 03:53:53 pm »
I have tested GetImage of BGLCanvas and its giving me same result, there is a gap in the canvas and I do not recognize what is it exactly, but I know its about using shaders, because when I use BGLFrame buffers separately in a test project its completely fit. You can see what I mean in the ScreenShot attached.

For simplicity of test I have removed the codes about vertical blur shader.

Any Idea why its happening??

Any help appreciated prior
Regards   

Code: Pascal  [Select]
  1.  
  2. procedure TForm1.scenePaint(Sender: TObject);
  3. var
  4.   bmp: TBGRACustomBitmap;
  5. begin
  6.   if not TexLoaded then
  7.     Exit;
  8.   BGLViewPort(w, h, BGRAWhite);
  9.  
  10.   //allocate target for horizontal blur
  11.   hb := TBGLFrameBuffer.Create(w, h);
  12.   BGLCanvas.ActiveFrameBuffer := hb;
  13.  
  14.   //configure shader
  15.   hs.ProjectionMatrix := BGLCanvas.ProjectionMatrix;
  16.   hs.TextureSize := Point(w, h);
  17.   BGLCanvas.Lighting.ActiveShader := hs;
  18.   hs.Sigma := sig;
  19.   //
  20.   BGLCanvas.PutImage(0, 0, tex);
  21.  
  22.   //render result
  23.   BGLCanvas.ActiveFrameBuffer := nil;
  24.   BGLCanvas.Lighting.ActiveShader := nil;
  25.   BGLCanvas.PutImage(0, 0, hb.Texture);
  26.   hb.Free;
  27.  
  28.   scene.SwapBuffers;
  29.  
  30.   bmp := BGLCanvas.GetImage(0, 0, BGLCanvas.Width, BGLCanvas.Height);
  31.   bmp.SaveToFile('Pics\GaussBlur1.png');
  32.   bmp.Free;
  33. end;    
  34.  
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. begin
  38.   w := 900;
  39.   h := 506;
  40.   Form1.Width := w;
  41.   Form1.Height := h;
  42.   WriteLn(w, ' , ', h);
  43.   scene := TOpenGLControl.Create(Self);
  44.   with scene do
  45.   begin
  46.     Parent := Self;
  47.     Width := w;
  48.     Height := h;
  49.     OnPaint := @scenePaint;
  50.     AutoResizeViewport := True;
  51.   end;
  52.   sig := 1;
  53. end;
  54.  
  55. procedure TForm1.FormShow(Sender: TObject);
  56. begin
  57.   tex := BGLTexture('Pics\1.jpg');
  58.   hs := TMyShaderHoriz.Create(BGLCanvas);
  59.   vs := TMyShaderVert.Create(BGLCanvas);
  60.   TexLoaded := True;
  61. end;          
  62.  
  63.  
  64.  
« Last Edit: March 15, 2017, 04:10:21 pm by simin_sh »
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #66 on: March 15, 2017, 05:08:35 pm »
Regardless of the problem of size of the picture, I have a question about quality and appearance of Gauss blur.

When I compare Gauss blur we have made in OpenGL with the fastBlur in Lazpaint, it seems that the radius has at least 50% smaller size of the sigma in the GLSL Formula that I pass as the blur depth, and the quality is different too.
You can see the compare I tested in the video file that I uploaded here:
https://www.dropbox.com/s/ebnt80wgug9k02a/blur.zip?dl=0

Any idea or suggestions??

Regards
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

circular

  • Hero Member
  • *****
  • Posts: 2570
    • Personal webpage
Re: Fast hardware image blur
« Reply #67 on: March 15, 2017, 06:40:32 pm »
Maybe the parameter with the projection matrix does not work. If the width and height are equal, do you still have the problem?

About the radius, it is expected to be different than the sigma value. The radius is something like sqrt(2) times bigger than the sigma. We could try to emulate the fast blur with GLSL to see if that's similar.
Conscience is the debugger of the mind

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #68 on: March 16, 2017, 10:06:29 am »
Maybe the parameter with the projection matrix does not work. If the width and height are equal, do you still have the problem?

Yes I have tested it before and there is still a gap.
You can see the result of blur when I use a picture of size 506*506 attached.
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

circular

  • Hero Member
  • *****
  • Posts: 2570
    • Personal webpage
Re: Fast hardware image blur
« Reply #69 on: March 18, 2017, 05:38:54 pm »
Does it help using old style shading language (version 120 instead of 330)? This way you can use predefined variables for vertex and texture position.

See attached project
Conscience is the debugger of the mind

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #70 on: March 24, 2017, 02:35:42 pm »
Thank you so much Circular, yes its now okay when I use version 130 for GLSL.
I did not use GLSL 120 because it gave me the following error in the SS attached.

Now I need to try implement horizontal and vertical shaders in one shader, and then need to test other blurs like fast blur in GLSL, to have the blurs in lazpaint, which are a bit more soft and beautiful, I need to check them out.

Regards
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

circular

  • Hero Member
  • *****
  • Posts: 2570
    • Personal webpage
Re: Fast hardware image blur
« Reply #71 on: April 30, 2017, 09:19:57 pm »
Hello there!

I have implemented radial blur and motion blur in BGRAOpenGL in latest version.

Simply write tex.FilterBlurMotion or tex.FilterBlurRadial with adequate parameters where tex is an IBGLTexture.

http://forum.lazarus.freepascal.org/index.php/topic,24239.msg244982.html#msg244982

Regards
Conscience is the debugger of the mind

simin_sh

  • Full Member
  • ***
  • Posts: 137
Re: Fast hardware image blur
« Reply #72 on: May 01, 2017, 08:05:35 am »
Hello there!

I have implemented radial blur and motion blur in BGRAOpenGL in latest version.

Simply write tex.FilterBlurMotion or tex.FilterBlurRadial with adequate parameters where tex is an IBGLTexture.

http://forum.lazarus.freepascal.org/index.php/topic,24239.msg244982.html#msg244982

Regards

GREAT, I will see them as soon as possible.
Thank you
OS Windows 10 - Lazarus 1.7 - FPC 3.1.1

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus