Ooops
November 28, 2020, 02:25:47 PM

Author Topic: [bb] Realistically Modeled Motion Blur Effect by ClayPigeon [ 1+ years ago ]  (Read 537 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Realistically Modeled Motion Blur Effect
Author : ClayPigeon
Posted : 1+ years ago

Description : I noticed that a lot of the motion blur effects in the code archives are actually just trail effects. I made this motion blur effect in order to simulate how motion blur is caused in real life. Motion blur is the byproduct of an object of interest moving during a camera's exposure. I simulate this by overlaying several renders of different RenderWorld tween states. Change the "layers" constant to change the nubmer of blur passes (quality). The higher the number, the faster objects can move without artifacts appearing. Change buffer_size to any power-of-2 number that is smaller than both the width and height of your graphics mode in order to increase the resolution of the blur effect. You can also change the EntityAlpha of the blur quads to make the effect more prominent. I can get a decent framerate on my laptop with these settings, and greater than 60 FPS on my PC with the same settings. Enjoy!

-If you want to pause it to examine the effect, just grab the top bar of the window and if will freeze. :)


Code :
Code: BlitzBasic
  1. AppTitle "Motion Blur"
  2. Graphics3D 640,480,0,2
  3. SetBuffer BackBuffer()
  4. SeedRnd MilliSecs()
  5.  
  6. Const layers% = 8
  7.  
  8. Global buffer_size% = 256
  9.  
  10. Dim blurtex%(layers-1)
  11. Dim blurquad%(layers-1)
  12.  
  13. For i = 0 To layers-1
  14.         blurtex(i) = CreateTexture(buffer_size,buffer_size)
  15. Next
  16.  
  17. Global objecttex = CreateTexture(128,128)
  18. SetBuffer TextureBuffer(objecttex)
  19. Color 255,255,0
  20. Rect 0,0,128,128
  21. Color 0,127,255
  22. Rect 0,0,64,64,True
  23. Rect 64,64,64,64,True
  24. SetBuffer BackBuffer()
  25.  
  26. Global camera% = CreateCamera()
  27. CameraRange camera,0.1,1000
  28.  
  29. Global cube% = CreateCube()
  30. PositionEntity cube,0,0,3
  31. EntityTexture cube,objecttex
  32.  
  33. Global clear% = CreateMesh()
  34. Global surf% = CreateSurface(clear)
  35. AddVertex(surf,-1,1,0)
  36. AddVertex(surf,1,1,0)
  37. AddVertex(surf,1,-1,0)
  38. AddVertex(surf,-1,-1,0)
  39. AddTriangle(surf,0,1,2)
  40. AddTriangle(surf,0,2,3)
  41. EntityColor clear,0,0,0
  42. PositionEntity clear,0,0,1
  43. EntityOrder clear,-1
  44.  
  45. For i = 0 To layers-1
  46.         blurquad(i) = CreateMesh()
  47.         surf = CreateSurface(blurquad(i))
  48.         AddVertex(surf,-1,1,0,0,0)
  49.         AddVertex(surf,1,1,0,1,0)
  50.         AddVertex(surf,1,-1,0,1,1)
  51.         AddVertex(surf,-1,-1,0,0,1)
  52.         AddTriangle(surf,0,1,2)
  53.         AddTriangle(surf,0,2,3)
  54.         EntityTexture blurquad(i),blurtex(i)
  55.         PositionEntity blurquad(i),0,0,1
  56.         EntityFX blurquad(i),1
  57.         EntityAlpha blurquad(i),0.125
  58.         EntityOrder blurquad(i),-1-i
  59. Next
  60.  
  61. While Not KeyHit(1)
  62.         Cls
  63.        
  64.         CaptureWorld
  65.        
  66.         TurnEntity cube,4,8,12
  67.        
  68.         UpdateWorld
  69.         CameraViewport camera,0,0,buffer_size,buffer_size
  70.         HideEntity clear
  71.         For i = 0 To layers-1
  72.                 HideEntity blurquad(i)
  73.         Next
  74.         CameraViewport camera,0,0,buffer_size,buffer_size
  75.         For i = 0 To layers-1
  76.                 RenderWorld (i+1)/Float(layers)
  77.                 CopyRect 0,0,buffer_size,buffer_size,0,0,BackBuffer(),TextureBuffer(blurtex(i))
  78.         Next
  79.         CameraViewport camera,0,0,GraphicsWidth(),GraphicsHeight()
  80.         ShowEntity clear
  81.         For i = 0 To layers-1
  82.                 ShowEntity blurquad(i)
  83.         Next
  84.         RenderWorld
  85.        
  86.         Flip True
  87. Wend
  88.  
  89. End


Comments :


Subirenihil(Posted 1+ years ago)

 
Code: [Select]
EntityAlpha blurquad(i),0.125Should be
Code: [Select]
EntityAlpha blurquad(i),1.0/layersVery nicely done.


ClayPigeon(Posted 1+ years ago)

 I know, I this is just a bare-bones version of it. I made this change after I uploaded it as well as several other changes. If enough people want it, I'll upload a better updated version. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal