December 04, 2020, 11:20:31 AM

Author Topic: [bb] Realtime Vertex lights by RifRaf [ 1+ years ago ]  (Read 735 times)

Offline BlitzBot

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

Description : Just a vertex light demo, can be expanded.  Puki came up with this idea, and may have a better system.   But since his code was not made available I took a quick whack at it.    Nothing amazing for sure, and limited applications.  You would have to plan your area with this system in mind to make any real use of it. And try to either limit light range or number of lights ect.   Ill expand on this when I have time.

Code :
Code: BlitzBasic
  1. Graphics3D 640,480,32,2
  2. ;Wireframe True
  3.         camera=CreateCamera()
  4.         PositionEntity camera,-15,40,-50
  5.         ;create some random junk
  6.         For i=1 To 2
  7.         sc=Rand(1,10)
  8.         Cube=CreateSphere(12)
  9.         ScaleMesh cube,sc,sc,sc:EntityPickMode cube,2,True
  10.         createfakelight_Receiver(cube)
  11.         PositionEntity cube,Rand(-20,20),Rand(-20,20),Rand(-20,20)
  12.         Next
  13.  
  14.         For i=-5 To 5
  15.                 For ii=-5 To 5
  16.                 land=createsquare(2)
  17.                     ScaleMesh land,10,1,10
  18.                 PositionEntity land,i*10,-3,ii*10
  19.                     createfakelight_Receiver(land)
  20.             Next
  21.         Next
  22.  
  23.     globallight=createfakelight(100,500,100,38,38,38,500)
  24.         light1=createfakelight(10,5,10,0,0,255,53.5)
  25.         light2=createfakelight(10,5,10,255,0,0,53.5)
  26.         lightvisual=CreateCube()
  27.         lightvisual2=CreateCube()
  28.         ; put a visual cube on the lights
  29.         EntityParent lightvisual,light1,False
  30.         EntityParent lightvisual2,light2,False
  31.         TranslateEntity light1,0,10,20
  32.         TranslateEntity light2,0,10,-20
  33.         PointEntity camera,cube
  34.  
  35.  
  36.         ; update it all
  37.         While Not KeyDown(1)
  38.  
  39.                 MoveEntity light1,0,0,2
  40.                 TurnEntity light1,0,1.5,0
  41.                 MoveEntity light2,0,0,-.25
  42.                 TurnEntity light2,0,-.5,0
  43.  
  44.                 lightfakereceivers()
  45.                 UpdateWorld()
  46.                 RenderWorld
  47.                 Flip
  48.         Wend
  49.         End
  50.  
  51.  
  52. Type FakeLight
  53.  Field Ent
  54.  Field r,g,b
  55.  Field range#
  56.  Field active
  57. End Type
  58.  
  59. Type FakeLightReceiver
  60.  Field ent    ;just the entity handle
  61. End Type
  62.  
  63. Function CreateFakeLight(x#,y#,z#,r#,g#,b#,range#)
  64.  fl.fakelight=New fakelight
  65.  flent=CreatePivot()
  66.  PositionEntity flent,x,y,z
  67.  fl
  68. =r
  69.  flg=g
  70.  fl=b
  71.  fl
  72. ange=range
  73.  flactive=1
  74.  Return flent
  75. End Function
  76.  
  77. Function FakeLightOnOFF(toggle=0)
  78.  For fl.fakelight=Each fakelight
  79.         If flent=ent Then
  80.        flactive=toggle
  81.        Exit
  82.     EndIf
  83.  Next
  84. End Function  
  85.  
  86. Function SetFakeLightRange(ent,newrange#)
  87.  For fl.fakelight=Each fakelight
  88.         If flent=ent Then
  89.         fl
  90. ange=newrange#
  91.         Exit
  92.     EndIf
  93.  Next
  94. End Function
  95.  
  96. Function SetFakeLightRGB(ent,newr,newg,newb)
  97.  For fl.fakelight=Each fakelight
  98.         If flent=ent Then
  99.         fl
  100. =newr
  101.         flg=newg
  102.         fl=newb
  103.         Exit
  104.     EndIf
  105.  Next
  106. End Function
  107.  
  108. Function CreateFakeLight_Receiver(ent,fx=3)
  109. flr.fakelightreceiver=New fakelightreceiver
  110. flrent=ent
  111. EntityFX ent,fx
  112. End Function
  113.  
  114.  
  115.  
  116. Function LightFakeReceivers()
  117. For flr.FakeLightReceiver=Each FakeLightReceiver
  118.         LightMesh flrent,-255,-255,-255
  119.         For fl.fakelight=Each fakelight
  120.                 If flactive=1 And EntityDistance(flrent,flent)=<(fl
  121. ange*4) Then
  122.                 If EntityVisible (flent,flrent) Then
  123.                                 TFormPoint 0,0,0,flent,flrent
  124.                                 LightMesh flrent,fl
  125. ,flg,fl,fl
  126. ange*.25,TFormedX(),TFormedY(),TFormedZ()
  127.                         EndIf                                  
  128.                 EndIf
  129.         Next
  130. Next
  131. End Function
  132.  
  133. Function createsquare(segs#=2,parent=0)
  134.     mesh=CreateMesh( parent )
  135.     surf=CreateSurface( mesh )
  136.     l# =-.5
  137.     b# = -.5
  138.     tvc= 0
  139.     Repeat
  140.       u# = l + .5
  141.       v# = b + .5
  142.       AddVertex surf,l,0,b,u,1-v
  143.       tvc=tvc + 1
  144.       l = l + 1/segs
  145.       If l > .501 Then
  146.         l = -.5
  147.         b = b + 1/segs
  148.       End If
  149.     Until b > .5
  150.     vc# =0
  151.     Repeat
  152.       AddTriangle (surf,vc,vc+segs+1,vc+segs+2)
  153.       AddTriangle (surf,vc,vc+segs+2,vc+1)
  154.       vc = vc + 1
  155.       tst# =  ((vc+1) /(segs+1)) -Floor ((vc+1) /(segs+1))
  156.       If (vc > 0) And (tst=0) Then
  157.         vc = vc + 1
  158.       End If
  159.     Until vc=>tvc-segs-2
  160.     UpdateNormals mesh
  161.     Return mesh
  162. End Function


Comments :


puki(Posted 1+ years ago)

 Not bad - for a beginner.:)


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal