Hi Circular and thank you for the demo,Cool.
I didnt know BGRABitmap can do these stuff this easily :D . I will play with it more but I can understand whet you said about blur "that does the blur (you may need to derive the class to add "variables")".
Also please add a simple demo when you add an abilityYes.
About blur speed, I tested again BGRABitmap blur and used image from the linked page and in Normal mode with r=10 it takes 700ms in my system (that is not old) and in Fast mode it takes 90 ms. Are you sure it is optimized like that or my machine is heavily slow? (I checked your code and it seems like that but I cant understand why is there such a huge difference)In Normal mode, it doesn't use the optimisation with box blurs. Only fast blur with radius >= 10 does.
In Normal mode, it doesn't use the optimisation with box blurs. Only fast blur with radius >= 10 does.I just tested and it takes 62ms for r=9 and 90 for r=11. it seems not not to me it has a much difference and I expect faster result.
I can't understand what you said about blur "that does the blur (you may need to derive the class to add "variables")".Oh ok. I suggest to look at the example I posted, and look at the GLSL files. There is the code for the shader. And that's where you would need to put some other code.
I just tested and it takes 62ms for r=9 and 90 for r=11. it seems not not to me it has a much difference and I expect faster result.Surprising. Well the fast blur without box blur is already optimized so the difference is not that big with a small radius. The difference is significant with a radius like 80 for example. To see the difference, you would need to comment out the "if" block in the fast blur where it calls the box blur.
f you have to apply the filter several times in order to get a more strong blur effect, the only thing you have to do is ping-pong between two framebuffers and apply the shaders to the result of the previous step.How can I do such thing in BGL?
Hi
I was testing Circular testshader1 project in this post:
http://forum.lazarus.freepascal.org/index.php/topic,30012.msg211701.html#msg211701
with the new fragment glsl code in this post for fast blur:
http://forum.lazarus.freepascal.org/index.php/topic,30012.msg224043.html#msg224043
and I got this error you can see in the picture attached, then I set the version in the code "440" because my OpenGL version is 4.4, but it seams that the version in TBGLShader3D did not assign correctly, or I am not setting the version correctly in the create shader function in UMyShader class, and I do not know where is the problem with glsl version. Here is the code :
constructor TMyShader.Create(ACanvas: TBGLCustomCanvas); begin inherited Create(ACanvas, ReadFileToString('mix.vertex.glsl'), ReadFileToString('mix.fragment.glsl'), '', '440'); FFadeFactorUniform := UniformSingle['fade_factor']; FTexturesUniform[0] := UniformInteger['textures[0]']; end;
I am using windows 10, Lazarus 1.6 and BGRABitmap from Git.
Any help appreciated prior
Indeed framebuffers are not implemented yet and that would be the way to go.
I've been quite busy but I guess now I will have a bit of free time. I am not sure how long it would take, but probably 6 hours would do. Now I just have to find 6 hours in my weekends.
You're welcome.
Reading pixels is not implemented yet but that's of course something we can add.
I tested a ping pong between buffers for a deeper blur, I think its the right way, but I have a problem in the size of texture coordinates and the control in draw, you can see it when draw the blured picture on control. any idea how to fix it??
Maybe it is because of the problem you said about flip, or the glsl code, I am not sure.
Here is my code
and I attached the test project with the sample pic I tested.
Any help appreciated prior
Regards
procedure TForm1.scenePaint(Sender: TObject); var n, i: integer; begin if not TexLoaded then Exit; BGLViewPort(scene.Width, scene.Height, BGRAWhite); //allocate target for horizontal blur //hb=horiz buffer, vb=vert buffer, hs=horiz shader, vs=vert shader hb := TBGLFrameBuffer.Create(tex.Width, tex.Height); BGLCanvas.ActiveFrameBuffer := hb; //configure shader hs.ProjectionMatrix := BGLCanvas.ProjectionMatrix; hs.TextureSize := Point(tex.Width, tex.Height); BGLCanvas.Lighting.ActiveShader := hs; tex.Draw(0, 0); //perform horiz blur //allocate target for vertical blur vb := TBGLFrameBuffer.Create(tex.Width, tex.Height); BGLCanvas.ActiveFrameBuffer := vb; //configure shader vs.ProjectionMatrix := BGLCanvas.ProjectionMatrix; vs.TextureSize := Point(tex.Width, tex.Height); BGLCanvas.Lighting.ActiveShader := vs; hb.Texture.Draw(0, 0); //perform vert blur on horizontally blurred image //Apply blur n times n := 100; for i := 0 to n - 1 do begin //allocate target for horizontal blur BGLCanvas.ActiveFrameBuffer := hb; //configure shader BGLCanvas.Lighting.ActiveShader := hs; vb.Texture.Draw(0, 0); //perform horiz blur //allocate target for vertical blur BGLCanvas.ActiveFrameBuffer := vb; //configure shader BGLCanvas.Lighting.ActiveShader := vs; hb.Texture.Draw(0, 0); //perform vert blur on horizontally blurred image end; //render result BGLCanvas.ActiveFrameBuffer := nil; BGLCanvas.Lighting.ActiveShader := nil; vb.Texture.FlipY.Draw(0, 0); //draw on control vb.Free; hb.Free; scene.SwapBuffers; end;
it takes 30ms for a picture of size 900*600 (regardless of sigma value) and its too much different from what it should be!Try to precalculate sqrt(2*PI) to a single float value. Calculator says it's 2.506628274631000502415765284811 ... Leave a few digits out for it to accept.
it takes 30ms for a picture of size 900*600 (regardless of sigma value) and its too much different from what it should be!Try to precalculate sqrt(2*PI) to a single float value. Calculator says it's 2.506628274631000502415765284811 ... Leave a few digits out for it to accept.
You can also try with a constant weight to see if it is faster.
simin_sh You will release it? It will be nice to have opengl blur in bgrabitmap, I just need it to use in a project for the graphics contest, just for fun.
Thanks you both for all this.
@Circular, you will include a blur demo in bgrabitmap or maybe somewhere in another repository?
@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.
I've added BGLCanvas.GetImage. It returns a TBGRABitmap object that you can save.
Maybe the parameter with the projection matrix does not work. If the width and height are equal, do you still have the problem?
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