November 24, 2020, 06:54:00 AM

Author Topic: [bb] DreamFilter by Afrohorse [ 1+ years ago ]  (Read 730 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] DreamFilter by Afrohorse [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : DreamFilter
Author : Afrohorse
Posted : 1+ years ago

Description : Here's a full-screen filter that can be used as a static screen filter, dreamy FMV sequences, or just an overall filter to change the look of your game.

However, I must warn you its quite expensive fill-rate wise - its based on the feedback method and includes a copy rect back from the frames backbuffer (as blitz3d cannot yet render to a texture).

Thanks to the guys on the blitz forums, tests have found that on the high end graphics cards (Radeon 9700+ & GeForce3 upwards) you can get rates around 150-230 fps. Where as the low end of the scale (TNT2 Model/64 pro & Matrox G400max) you get rates of 20-30 fps.

Enjoy :)


Code :
Code: BlitzBasic
  1. ;===============================================================================
  2. ; Dream Filter - Ian Lindsey (Afrohorse)
  3. ; ------------
  4. ; 03 Feb 2004
  5. ;
  6. ; The scene is rendered to a smaller sized viewport and copied into a texture.
  7. ; The texture is placed onto a sprite that overlays the entire screen, using
  8. ; an additive blend - this sprite also is scaled slightly larger than the screen.
  9. ; (The filtering will blur the scene - like depth of field)
  10. ;
  11. ; The sprite is then fed back into the next frame (motion blur), so that the
  12. ; additive blend burns the brighter parts of the scene into the texture. The
  13. ; slight scale up of the sprite will add a bloom effect around these bright parts
  14. ; (High dynamic range).
  15. ;
  16. ; Example Usage:
  17. ; --------------
  18. ;
  19. ; <Program Start>
  20. ; Create the camera (use Global g_Camera)
  21. ; NBDreamFilter_Create()
  22. ;
  23. ; <Main Loop>
  24. ; Program Update code..
  25. ; NBDreamFilter_Update()
  26. ;
  27. ; RenderWorld
  28. ; Flip
  29. ; <End Of Main Loop>
  30. ;
  31. ; <Program End>
  32. ; NBDreamFilter_Destroy()
  33. ;
  34. ; =====================================================================
  35. ; NOTE: The scenes camera should be placed in a global variable called
  36. ;       g_Camera
  37. ; =====================================================================
  38. ;
  39. ;
  40. ;===============================================================================
  41.  
  42. ; Includes /////////////////////////////////////////////////////////////////////
  43.  
  44. ; Constants ////////////////////////////////////////////////////////////////////
  45.  
  46. ; Tweakable Values
  47. Const k_HDRTextureSize  = 256           ; Blur texture size, must be power of 2
  48. Const k_HDRMotionZoom#  = 1.022         ; The amount the blur sprite scales
  49. Const k_HDRBlurFeedBack = 220           ; 0 - 255 The amount of previous frame to feedback
  50. Const k_HDRBlurFilter   = 100           ; 0 - 255 The amount of the filter to overlay (additive) to the scene
  51.  
  52. Const k_HDRZSpritePos#  = 1.1
  53. Const k_HDRSpriteOffs#  = 0.001
  54.  
  55. ; Globals //////////////////////////////////////////////////////////////////////
  56. Global g_BlurTex
  57. Global g_BlurSprite
  58.  
  59. ; Functions ////////////////////////////////////////////////////////////////////
  60.  
  61. ;///////////////////////////////////////////////////////////////////////////////
  62. ; Creates the Dream filter
  63. ;///////////////////////////////////////////////////////////////////////////////
  64. Function NBDreamFilter_Create()
  65.        
  66.         ; Create a fullscreen sprite
  67.         spr             = CreateMesh(g_Camera)
  68.         sf              = CreateSurface(spr)
  69.        
  70.         ; Make a quad
  71.         AddVertex   sf, -1, 1, 0, 0, 0
  72.         AddVertex   sf,  1, 1, 0, 1, 0
  73.         AddVertex   sf, -1,-1, 0, 0, 1
  74.         AddVertex   sf,  1,-1, 0, 1, 1
  75.                
  76.         AddTriangle sf, 0, 1, 2
  77.         AddTriangle sf, 3, 2, 1
  78.        
  79.         ; Set up the sprites position, scale etc...
  80.         zpos#           = k_HDRZSpritePos#
  81.         range#          = k_HDRMotionZoom*zpos#
  82.         PositionEntity  spr,  -k_HDRSpriteOffs#, k_HDRSpriteOffs#, zpos#
  83.         ScaleEntity     spr,  range#, range#, 1.0
  84.         EntityOrder     spr,  -10000
  85.        
  86.         ; Set full colour & additive blend
  87.         EntityFX                spr, 1
  88.         EntityBlend             spr, 3
  89.         g_BlurSprite  =         spr
  90.        
  91.         ; Create blur texture
  92.         g_BlurTex = CreateTexture(k_HDRTextureSize, k_HDRTextureSize)
  93.         EntityTexture spr, g_BlurTex
  94.        
  95. End Function
  96.  
  97. ;///////////////////////////////////////////////////////////////////////////////
  98. ; Destroys the Dream filter
  99. ;///////////////////////////////////////////////////////////////////////////////
  100. Function NBDreamFilter_Destroy()
  101.  
  102.         FreeTexture g_BlurTex
  103.         FreeEntity  g_BlurSprite
  104.        
  105. End Function
  106.  
  107.  
  108. ;///////////////////////////////////////////////////////////////////////////////
  109. ; Updates the Dream filter
  110. ;///////////////////////////////////////////////////////////////////////////////
  111. Function NBDreamFilter_Update()
  112.  
  113.         ; Set the viewport to the same size as the blur texture
  114.         CameraViewport g_Camera, 0, 0, k_HDRTextureSize, k_HDRTextureSize
  115.        
  116.         ; Set the blur feedback value (Additive)
  117.         col = k_HDRBlurFeedBack
  118.         EntityColor g_BlurSprite, col,col,col
  119.  
  120.         ; Render the scene (including the blur sprite and copy it into the texture)
  121.         RenderWorld
  122.         CopyRect  0,0,k_HDRTextureSize,k_HDRTextureSize, 0, 0, BackBuffer(), TextureBuffer(g_BlurTex)
  123.        
  124.         ; Reset the viewport to fullscreen
  125.         CameraViewport g_Camera,0,0,GraphicsWidth(),GraphicsHeight()
  126.        
  127.         ; Set the blur filter value (Additive)
  128.         col = k_HDRBlurFilter
  129.         EntityColor g_BlurSprite, col,col,col
  130.        
  131. End Function


Comments :


Clyde(Posted 1+ years ago)

 Awesome mate :)


tyoud(Posted 1+ years ago)

 To use this with the castle demo:I made the Create() and Update() functions take g_Camera as an argumentUsed F2 to turn it off and on, right after the code to toggle wireframe off and on:
Code: [Select]
If KeyHit(60) ; 'F2' key for dreamworld toggle
If (dreamworld) Then
dreamworld = Not dreamworld
NBDreamFilter_Destroy()
Else
dreamworld = Not dreamworld
NBDreamFilter_Create(Camera1.ChaseCamcamera)
EndIf
EndIf
and just called the Update() function before RenderWorld():
Code: [Select]
; if in dreamworld, show that
If (dreamworld) Then
NBDreamFilter_Update(Camera1.ChaseCamcamera)
EndIf

RenderWorld tween


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal