March 04, 2021, 12:33:50 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Effects
»
[bb] Realtime Vertex lights by RifRaf [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Realtime Vertex lights by RifRaf [ 1+ years ago ] (Read 773 times)
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
Graphics3D
640
,
480
,
32
,
2
;Wireframe True
camera=
CreateCamera
(
)
PositionEntity
camera,-
15
,
40
,-
50
;create some random junk
For
i=
1
To
2
sc=
Rand
(
1
,
10
)
Cube=
CreateSphere
(
12
)
ScaleMesh
cube,sc,sc,sc:
EntityPickMode
cube,
2
,
True
createfakelight_Receiver
(
cube
)
PositionEntity
cube,
Rand
(
-
20
,
20
)
,
Rand
(
-
20
,
20
)
,
Rand
(
-
20
,
20
)
Next
For
i=-
5
To
5
For
ii=-
5
To
5
land=createsquare
(
2
)
ScaleMesh
land,
10
,
1
,
10
PositionEntity
land,i*
10
,-
3
,ii*
10
createfakelight_Receiver
(
land
)
Next
Next
globallight=createfakelight
(
100
,
500
,
100
,
38
,
38
,
38
,
500
)
light1=createfakelight
(
10
,
5
,
10
,
0
,
0
,
255
,
53.5
)
light2=createfakelight
(
10
,
5
,
10
,
255
,
0
,
0
,
53.5
)
lightvisual=
CreateCube
(
)
lightvisual2=
CreateCube
(
)
; put a visual cube on the lights
EntityParent
lightvisual,light1,
False
EntityParent
lightvisual2,light2,
False
TranslateEntity
light1,
0
,
10
,
20
TranslateEntity
light2,
0
,
10
,-
20
PointEntity
camera,cube
; update it all
While
Not
KeyDown
(
1
)
MoveEntity
light1,
0
,
0
,
2
TurnEntity
light1,
0
,
1.5
,
0
MoveEntity
light2,
0
,
0
,-.25
TurnEntity
light2,
0
,-.5,
0
lightfakereceivers
(
)
UpdateWorld
(
)
RenderWorld
Flip
Wend
End
Type
FakeLight
Field
Ent
Field
r,g,b
Field
range#
Field
active
End Type
Type
FakeLightReceiver
Field
ent
;just the entity handle
End Type
Function
CreateFakeLight
(
x#,y#,z#,r#,g#,b#,range#
)
fl.fakelight=
New
fakelight
flent=
CreatePivot
(
)
PositionEntity
flent,x,y,z
fl
=r
flg=g
fl=b
fl
ange=range
flactive=
1
Return
flent
End Function
Function
FakeLightOnOFF
(
toggle=
0
)
For
fl.fakelight=
Each
fakelight
If
flent=ent
Then
flactive=toggle
Exit
EndIf
Next
End Function
Function
SetFakeLightRange
(
ent,newrange#
)
For
fl.fakelight=
Each
fakelight
If
flent=ent
Then
fl
ange=newrange#
Exit
EndIf
Next
End Function
Function
SetFakeLightRGB
(
ent,newr,newg,newb
)
For
fl.fakelight=
Each
fakelight
If
flent=ent
Then
fl
=newr
flg=newg
fl=newb
Exit
EndIf
Next
End Function
Function
CreateFakeLight_Receiver
(
ent,fx=
3
)
flr.fakelightreceiver=
New
fakelightreceiver
flrent=ent
EntityFX
ent,fx
End Function
Function
LightFakeReceivers
(
)
For
flr.FakeLightReceiver=
Each
FakeLightReceiver
LightMesh
flrent,-
255
,-
255
,-
255
For
fl.fakelight=
Each
fakelight
If
flactive=
1
And
EntityDistance
(
flrent,flent
)
=<
(
fl
ange*
4
)
Then
If
EntityVisible
(
flent,flrent
)
Then
TFormPoint
0
,
0
,
0
,flent,flrent
LightMesh
flrent,fl
,flg,fl,fl
ange*.25,
TFormedX
(
)
,
TFormedY
(
)
,
TFormedZ
(
)
EndIf
EndIf
Next
Next
End Function
Function
createsquare
(
segs#=
2
,parent=
0
)
mesh=
CreateMesh
(
parent
)
surf=
CreateSurface
(
mesh
)
l# =-.5
b# = -.5
tvc=
0
Repeat
u# = l + .5
v# = b + .5
AddVertex
surf,l,
0
,b,u,
1
-v
tvc=tvc +
1
l = l +
1
/segs
If
l > .501
Then
l = -.5
b = b +
1
/segs
End If
Until
b > .5
vc# =
0
Repeat
AddTriangle
(
surf,vc,vc+segs+
1
,vc+segs+
2
)
AddTriangle
(
surf,vc,vc+segs+
2
,vc+
1
)
vc = vc +
1
tst# =
(
(
vc+
1
)
/
(
segs+
1
)
)
-
Floor
(
(
vc+
1
)
/
(
segs+
1
)
)
If
(
vc >
0
)
And
(
tst=
0
)
Then
vc = vc +
1
End If
Until
vc=>tvc-segs-
2
UpdateNormals
mesh
Return
mesh
End Function
Comments :
puki(Posted 1+ years ago)
Not bad - for a beginner.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Effects
»
[bb] Realtime Vertex lights by RifRaf [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal