Ooops
January 26, 2021, 11:38:06 AM

Author Topic: [bb] anti alias/glow a single entity by Nate the Great [ 1+ years ago ]  (Read 612 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : anti alias/glow a single entity
Author : Nate the Great
Posted : 1+ years ago

Description : this program will allow you to add anti aliasing to a single entity.  Limitations are no animated models, and no alpha'd models but those never need aa anyway...

note that you can easily modify this code to have a glow effect although it was not meant for that.


Code :
Code: BlitzBasic
  1. Graphics3D 800,600,0,2
  2.  
  3. cam = CreateCamera()
  4. MoveEntity cam,0,0,-10
  5.  
  6. cub = CreateCube()
  7. EntityColor cub,100,100,255
  8. cubeaa.aamesh = createaamesh(cub,cam,9,.0033333,1,True,100,100,255)   ;the parameters are as follows.  entity you want to antialias, camera to do it in, layers,distance between layers, how "light" you want the aa, will the aa scale depending on how close the camera is?, red, green, blue for glow fx.
  9.  
  10.  
  11. lit = CreateLight()
  12. TurnEntity lit,90,0,0
  13.  
  14.  
  15. hideaaflag = False
  16.  
  17. While Not KeyDown(1)
  18.         Cls
  19.         TurnEntity cub,.3,.3,0
  20.         PositionEntity(cam,0,0,-200.0+MouseX()/4.0)
  21.         If hideaaflag = True Then
  22.                 hideaa(cubeaa.aamesh)
  23.         Else
  24.                 showaa(cubeaa.aamesh)
  25.         EndIf
  26.         If KeyHit(57) Then hideaaflag = 1-hideaaflag
  27.        
  28.         updateaameshes(cam)
  29.        
  30.         RenderWorld()
  31.         Flip
  32. Wend
  33.  
  34.  
  35. Type AAMesh
  36.         Field entity
  37.         Field ccount    ;copy count, number of times to render the mesh
  38.         Field gdist#            ;gap- distance between meshes
  39.         Field SDist             ;Starting distance from the camera.
  40.         Field cam
  41.         Field meshes[10]
  42.         Field hide
  43.         Field scale
  44. End Type
  45.  
  46. Function CreateAAMesh.AAMesh(entity,cam,ccount,gdist#,alphadiv#,scale,r = 255,g = 255,b = 255,sdist# = 0)
  47.         Local a.aamesh = New aamesh
  48.         aentity = entity
  49.         account = ccount
  50.         agdist = gdist
  51.         asdist = sdist
  52.         ascale = scale
  53.         acam = cam
  54.         If sdist = 0 Then
  55.                 asdist = EntityDistance(cam,aentity)
  56.         EndIf
  57.        
  58.         For i = 1 To ccount
  59.                 ameshes[i] = CopyMesh(entity)
  60.                 EntityAlpha ameshes[i],((1.0/(ccount+1))*(ccount+1-i))/alphadiv
  61.                 ScaleEntity(ameshes[i],i*gdist+1,i*gdist+1,i*gdist+1)
  62.                 PositionEntity(ameshes[i],EntityX(entity),EntityY(entity),EntityZ(entity))
  63.                 TurnEntity(ameshes[i],EntityPitch(entity),EntityYaw(entity),EntityRoll(entity))
  64.                 EntityColor ameshes[i],r,g,b
  65.                 EntityParent(ameshes[i],entity)
  66.         Next
  67.        
  68.         Return a.aamesh
  69. End Function
  70.  
  71.  
  72. Function hideAA(a.aamesh)
  73.         ahide = True
  74. End Function
  75. Function showAA(a.aamesh)
  76.         ahide = False
  77. End Function
  78.  
  79.  
  80. Function UpdateAAMeshes(cam)
  81.         For a.aamesh = Each aamesh
  82.                 If acam = cam And ahide = False Then
  83.                         For i = 1 To account
  84.                                 ShowEntity ameshes[i]
  85.                                 If ascale = True Then
  86.                                         Local dist# = EntityDistance(aentity,cam)
  87.                                         Local scl# = (i*agdist*(dist#/asdist#))+1.0
  88.                                         ScaleEntity ameshes[i],scl,scl,scl
  89.                                 EndIf
  90.                                
  91.                         Next
  92.                 Else
  93.                         For i = 1 To account
  94.                                 HideEntity ameshes[i]
  95.                         Next
  96.                 EndIf
  97.         Next
  98. End Function


Comments :


stanrol(Posted 1+ years ago)

 cool


Nate the Great(Posted 1+ years ago)

 thanks rs


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal