Hey all, came up with this as an example of a cheap and cheerful way to lightmap a level, or even just give it your own custom look using vertex diffuse. It's quick enough to use after loading a level, so that's how I'd use it personally, load and position your map and then run each object through the light mapper function. It should not affect texturing bar some issues where you might want to change the contrast etc to get the look you want.
`Vertex Lightmap example by Van-B
null=make vector2(1)
null2=make vector3(2)
null3=make vector3(3)
null4=make vector3(4)
sync on
sync rate 60
autocam off
type lights
x# as float
y# as float
z# as float
range# as float
colr as integer
colg as integer
colb as integer
active as byte
endtype
dim light(32) as lights
`Setup light 0 as the default ambient light
l=0
light(l).colr=128
light(l).colg=128
light(l).colb=255
light(l).range#=1200
light(l).x#=0
light(l).y#=1000
light(l).z#=100
light(l).active=1
global ambient#=0.3
l=1
light(l).colr=255
light(l).colg=64
light(l).colb=0
light(l).range#=800
light(l).x#=0
light(l).y#=-400
light(l).z#=100
light(l).active=1
l=2
light(l).colr=0
light(l).colg=250
light(l).colb=32
light(l).range#=600
light(l).x#=-500
light(l).y#=50
light(l).z#=-200
light(l).active=1
`Make some random lights
for l=3 to 6
light(l).colr=rnd(255)
light(l).colg=255-light(l).colr
light(l).colb=255
light(l).range#=50+rnd(100)
light(l).x#=rnd(500)-250
light(l).y#=rnd(200)
light(l).z#=rnd(500)-250
light(l).active=1
next l
`Make to represent them
for l=0 to 5
make object sphere l+10,light(l).range#,8,8
position object l+10,light(l).x#,light(l).y#,light(l).z#
ghost object on l+10,2
disable object zwrite l+10
`set object light l+10,0
scale object l+10,-100,-100,-100
set object emissive l+10,rgb(light(l).colr,light(l).colg,light(l).colb)
set object specular l+10,rgb(light(l).colr,light(l).colg,light(l).colb)
set object ambience l+10,rgb(light(l).colr,light(l).colg,light(l).colb)
hide object l+10
next l
obj=100
position camera 200,500,200
for o=0 to 100
r=10+rnd(60)
make object sphere obj,r,5,5
position object obj,rnd(500)-250,r,rnd(500)-250
SC_setupObject obj,1,0
inc obj,1
next o
`random wall now
for y=0 to 10
for x=-10 to 10
make object sphere obj,25.2+(sin(rnd(360))*5.0),5,5
position object obj,(x*20)+(sin(rnd(360))*5.0),(y*20)+(sin(rnd(360))*5.0),0
SC_setupObject obj,1,0
inc obj,1
next x
next y
`Now step through all the objects and lightmap them
obj=100
while object exist(obj)=1
Lightmap(obj)
inc obj,1
endwhile
do
rotate camera mousey(),mousex(),0
move camera (upkey()-downkey())*5.0
for l=0 to 32
if light(l).active=1 and object exist(l+10)=1
if mouseclick()=2
show object l+10
else
hide object l+10
endif
endif
next l
sync
loop
function lightmap(obj)
convert object fvf obj ,338
set object light obj,0
perform checklist for object limbs obj
limbs=checklist quantity()-1
for lmb=0 to limbs
lock vertexdata for limb obj,lmb,2
verts=GET VERTEXDATA VERTEX COUNT()-1
for v=0 to verts
nx#=get vertexdata normals x(v)
ny#=get vertexdata normals y(v)
nz#=get vertexdata normals z(v)
if light(0).active=0
`No light 0 so start from black
r=0 : g=0 : b=0 : instances#=0.1 : result#=1.0
else
`Fake lighting based on dot product of light -> vertex and normal vectors
x#=get vertexdata position x(v)+limb position x(obj,lmb)
y#=get vertexdata position y(v)+limb position y(obj,lmb)
z#=get vertexdata position z(v)+limb position z(obj,lmb)
lx#=light(0).x#
ly#=light(0).y#
lz#=light(0).z#
set vector3 4,nx#,ny#,nz#
normalize vector3 2,4
set vector3 4,lx#-x#,ly#-y#,lz#-z#
normalize vector3 3,4
CROSS PRODUCT VECTOR3 4,2,3
`Seems to give better results with low poly meshes compared to LENGTH VECTOR3
result#=1.0-z vector3(4)
if result#<0 then result#=0
if result#>1 then result#=1
instances#=1.0
r=(light(0).colr*result#)*ambient#
g=(light(0).colg*result#)*ambient#
b=(light(0).colb*result#)*ambient#
endif
for l=0 to 32
if light(l).active=1
lx#=light(l).x#
ly#=light(l).y#
lz#=light(l).z#
x#=get vertexdata position x(v)+limb position x(obj,lmb)
y#=get vertexdata position y(v)+limb position y(obj,lmb)
z#=get vertexdata position z(v)+limb position z(obj,lmb)
inc x#,nx#/100.0
inc y#,ny#/100.0
inc z#,nz#/100.0
`SC_rayCastGroup ( groupNum, oldx, oldy, oldz, x, y, z, excludeObj )
hit=SC_rayCastGroup(1,lx#,ly#,lz#,x#,y#,z#,l+10)
if hit=0
range#=1.0-((range3D(lx#,ly#,lz#,x#,y#,z#)/light(l).range#))
if range#<0 then range#=0
if range#>1.0 then range#=1.0
inc r,light(l).colr*range#*(result#*2.0)
inc g,light(l).colg*range#*(result#*2.0)
inc b,light(l).colb*range#*(result#*2.0)
inc instances#,1.0
endif
endif
next l
if r>255 then r=255
if r<0 then r=0
if g>255 then g=255
if g<0 then g=0
if b>255 then b=255
if b<0 then b=0
set vertexdata diffuse v,rgb(r,g,b)
next v
unlock vertexdata
next lmb
endfunction
function range2D(ax#,az#,bx#,bz#)
set vector2 1,ax#-bx#,az#-bz# : result#=length vector2(1)
endfunction result#
function range3D(ax#,ay#,az#,bx#,by#,bz#)
set vector3 2,ax#-bx#,ay#-by#,az#-bz# : result#=length vector3(2)
endfunction result#