2D bloom filter possible?
Blitz3D Forums/Blitz3D Programming/2D bloom filter possible?
| ||
Is it possible to create a bloom filter that would work on a 2D scene instead of a 3D one, for example like Bouncers teapot demo but on flat objects like sprites? If anyone could provide a simple example that would be great as I have tried but cannot recreate the effect on a 2D scene sadly. Jason. |
| ||
yes, it is I don't remember where in the forums but there exist a version that works in 2D with pixelreadfast (and it's really fast) and very configurable. I will take a look to find it, but it's in the forums, not in the code archives, I guess. Sorry for not to be more helpful! I will try to find it... regards! |
| ||
Thats ok, if you find it please let me know as it sounds like just what I`m after. Jason. |
| ||
I've found it! :) If you point me how to put code in a box here, I will do it, or if you prefer, give me your mail address and I'll send you.. regards! |
| ||
Great. Here`s a link to the forum codes page. http://www.blitzmax.com/faq/faq_entry.php?id=2 Thanks for taking the time to find this for me. Jason. |
| ||
Ok, here it is!Graphics3D 1024,768,32,2 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight() RotateEntity light,45,45,45 TranslateEntity camera,0,0,-45 CameraRange camera,.001,100 anz=500 Dim s(anz) For i=0 To anz s(i)=CreateCube() PositionEntity s(i),Rnd(-20,20),Rnd(-20,20),Rnd(-20,20) EntityColor s(i),Rand(255),Rand(255),Rand(255) Next gloo_w#=64;128 gloo_h#=gloo_w#*(Float(GraphicsHeight())/Float(GraphicsWidth())); 0.75 Dim proc_array(gloo_w#,gloo_h#) tex=CreateTexture(gloo_w#,gloo_w#,256); Or 16 Or 32) quad=CreateQuad() PositionEntity quad,EntityX(camera,1),EntityY(camera,1),EntityZ(camera,1),1 EntityTexture quad,tex EntityFX quad,1 EntityBlend quad,3 TranslateEntity quad,-(1.0/1024.0),(1.0/1024.0),1.0 ;EntityColor quad,0,255,0 gloo_wrel#=GraphicsWidth()/gloo_w gloo_hrel#=GraphicsHeight()/gloo_h ; ************************************ MAIN *********************************** While KeyDown(1)=0 For i=0 To anz TurnEntity s(i),1,2,3 Next If KeyHit(57) do_gloom=do_gloom +1 If do_gloom>1 Then do_gloom=0 If do_gloom=0 Then HideEntity quad EndIf If do_gloom=1 Then ShowEntity quad EntityAlpha quad,0.95 ;1.0 EndIf EndIf If do_gloom=1 CameraViewport camera,0,0,gloo_w#,gloo_h# HideEntity quad RenderWorld() quick_blur(gloo_w#,gloo_h#,2) ShowEntity quad CopyRect 0,0,gloo_w#,gloo_h#,0,(gloo_w#-gloo_h#)/2,BackBuffer(),TextureBuffer(tex) CameraViewport camera,0,0,GraphicsWidth(),GraphicsHeight() EndIf RenderWorld() old_tt=tt tt=MilliSecs() Text 0,0,tt-old_tt Text 0,16,do_gloom Flip 0 Wend End Function quick_blur(w,h,passes=1) If passes<1 Then passes=1 passes=passes-1 SetBuffer BackBuffer() LockBuffer(BackBuffer()) For j=0 To h-1 For i=0 To w-1 proc_array(i,j)=ReadPixelFast(i,j) ;And $FFFFFF Next Next For dbass=0 To passes For j=0 To h-1 For i=1 To w-1 proc_array(i,j)=((proc_array(i,j)And $FEFEFF)Shr 1)+((proc_array(i-1,j)And $FEFEFF)Shr 1) Next For i=w-2 To 0 Step -1 proc_array(i,j)=((proc_array(i,j)And $FEFEFE)Shr 1)+((proc_array(i+1,j)And $FEFEFE)Shr 1) Next Next For i=0 To w-1 For j=1 To h-1 proc_array(i,j)=((proc_array(i,j)And $FEFEFF)Shr 1)+((proc_array(i,j-1)And $FEFEFF)Shr 1) Next For j=h-2 To 0 Step -1 proc_array(i,j)=((proc_array(i,j)And $FEFEFE)Shr 1)+((proc_array(i,j+1)And $FEFEFE)Shr 1) Next Next Next For j=0 To h-1 For i=0 To w-1 WritePixelFast i,j,proc_array(i,j) Next Next UnlockBuffer(BackBuffer()) End Function Function CreateQuad(parent=0) ; creates a quad, facing to the right side mesh=CreateMesh(parent) surf=CreateSurface(mesh) v0=AddVertex(surf, -1.0, 1.0,0, 0,0 ) v1=AddVertex(surf, 1.0, 1.0,0, 1,0 ) v2=AddVertex(surf, 1.0, -1.0,0, 1,1 ) v3=AddVertex(surf, -1.0, -1.0,0, 0,1 ) AddTriangle(surf,v0,v1,v2) AddTriangle(surf,v0,v2,v3) UpdateNormals mesh Return mesh I hope it'll be helpful! regards |
| ||
Neat. Thanks again, Jason. |
| ||
yeah, pretty neat indeed! :) |
| ||
did you ever see sswifts blurtexture() function? http://www.blitzbasic.com/codearcs/codearcs.php?code=754 this speeds the whole thing up:) |
| ||
see also this thread: http://www.blitzbasic.com/Community/posts.php?topic=54855 |