December 03, 2020, 08:10:35 PM

Author Topic: [bb] Glow Effect by mag. [ 1+ years ago ]  (Read 588 times)

Offline BlitzBot

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

Description : Create a Glow effect (like in Prince Of Persia - Sand of time) . Not really ;)

Code :
Code: BlitzBasic
  1. ;Glow effect
  2. ;Code by Mag. Idea from Sswift.
  3.  
  4. Graphics3D 640,480,32,2
  5. SetBuffer BackBuffer()
  6.  
  7. ; Create camera
  8. Global camera=CreateCamera()
  9. MoveEntity camera,3,3,0
  10. RotateEntity camera,30,30,0
  11.  
  12. light=CreateLight()
  13.  
  14. Global cube=CreateCube()
  15. PositionEntity cube,0,0,5
  16. tex0=CreateTexture(300,300)
  17. SetBuffer TextureBuffer(tex0)
  18. ClsColor 255,255,255
  19. Cls
  20. SeedRnd(MilliSecs())
  21. For k=1 To 50
  22.         Color Rand(256),Rand(256),Rand(256)
  23.         Rect Rand(600),Rand(600),Rand(600),Rand(600)
  24. Next
  25. EntityTexture cube,tex0
  26. SetBuffer BackBuffer()
  27.  
  28. ;glow setup
  29. s=1
  30. Global sizex=640/s
  31. Global sizey=480/s
  32. Global glowtexture=CreateTexture (384,384,256)
  33. Global sp=CreateSprite(camera)
  34. MoveEntity sp,-.25,-0.06,1.18
  35. EntityAlpha sp,.32
  36. ScaleTexture glowtexture,GraphicsWidth()/sizex,GraphicsHeight()/sizey
  37. EntityTexture sp,glowtexture
  38. TextureBlend glowtexture, 5
  39. While Not KeyDown( 1 )
  40.         TurnEntity cube,0.5,0.5,0.5
  41.         CameraViewport camera,0,0,sizex,sizey
  42.         RenderWorld
  43.         CopyRect 0,0,sizex,sizey,0,0,BackBuffer(),TextureBuffer(glowtexture)
  44.         CameraViewport camera,0,0,GraphicsWidth(),GraphicsHeight()
  45.        
  46.         RenderWorld
  47.         Flip
  48. Wend
  49.  
  50. End


Comments :


T-Head(Posted 1+ years ago)

 Hi,its very well! Exactly what I need!thx


Filax(Posted 1+ years ago)

 Great !


FredMe(Posted 1+ years ago)

 Excellent,I will used this idea for my FPS Engine !


Picklesworth(Posted 1+ years ago)

 This will be very useful for a strategy game with glowing objects, where they are all really small and in large numbers... Thus needing a fast routine that looks good from afar.


Barliesque(Posted 1+ years ago)

 It seems to work just as well, removing the first RenderWorld statement, which ought to give faster results in a complex scene.Try this slightly adjusted version...
Code: [Select]
;Glow effect
;Code by Mag. Idea from Sswift.

Graphics3D 640,480,32,2
SetBuffer BackBuffer()

; Create camera
Global camera=CreateCamera()
MoveEntity camera,3,3,0
RotateEntity camera,30,30,0

light=CreateLight()

Global cube=CreateCube()
PositionEntity cube,0,0,5
tex0=CreateTexture(300,300)
SetBuffer TextureBuffer(tex0)
ClsColor 255,255,255
Cls
SeedRnd(MilliSecs())
For k=1 To 50
Color Rand(256),Rand(256),Rand(256)
Rect Rand(600),Rand(600),Rand(600),Rand(600)
Next
EntityTexture cube,tex0
SetBuffer BackBuffer()

;glow setup
s=1
Global sizex=640/s
Global sizey=480/s
Global glowtexture=CreateTexture (384,384,256)
Global sp=CreateSprite(camera)
MoveEntity sp,-.25,-0.06,1.21
ScaleTexture glowtexture,GraphicsWidth()/sizex,GraphicsHeight()/sizey
EntityTexture sp,glowtexture

TextureBlend glowtexture, 5    ;Also try mode 2 ...and increase the Alpha from 0.44 to about 0.80
EntityAlpha sp, 0.44

While Not KeyDown( 1 )
TurnEntity cube,0.5,0.5,0.5
CameraViewport camera,0,0,sizex,sizey
; RenderWorld
CopyRect 0,0,sizex,sizey,0,0,BackBuffer(),TextureBuffer(glowtexture)
CameraViewport camera,0,0,GraphicsWidth(),GraphicsHeight()

RenderWorld
Flip
Wend

End



ingenium(Posted 1+ years ago)

 WOOOOOOOOOOOOOOOOOOWWWWW!!!!!!!!!!!!!


Nmuta(Posted 1+ years ago)

 Wow. Very nice.


puki(Posted 1+ years ago)

 This can be optimised further and can also be made more dynamic with regard to resizing.I'll expect an amened version within the week.Thank you.


Mustang(Posted 1+ years ago)

 Nice!


Buggy(Posted 1+ years ago)

 So nice!  Will definitely use this sometime!


RemiD(Posted 8 months ago)

 can somebody explain what is going on (the method) in this code ? it seems that "mag" tweaked it until it looks ok but without any clue of why he has configured it this way... [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal