Could someone see what I've done wrong here.
This is supposed to be a simple demo of Dark Lights in action but doesn't work as expected (see image and comments later in this popst):
` simple demo of DarkLIGHTS - but doesn't seem to work correctly
set display mode desktop width(), desktop height(), 32
sync on: sync rate 60: sync
randomize 140549
autocam off
position camera 0, 500, 0
point camera 0, 0, 0
global cx#
global cy#
cx# = camera angle x()
cy# = camera angle y()
load image "Polyphant01 TM Seamless v2.png", 1
lm start ` initialize the light map process
make object box 1, 500, 1, 500
texture object 1, 1
lm add collision object 1
lm add light map object 1
` the following objects will cast and receive shadows
for i = 2 to 10
make object sphere i, 50
texture object i, 1
lm add collision object i
lm add light map object i
position object i, rnd(400)-200, rnd(20)+25, rnd(400)-200
next i
` we need a light!
make object sphere 20, 5 ` this marks the light's position
position object 20, -250, 100, 100
lm add point light -250, 100, 100, 1200, 0, 1, 0 ` a nice green light
lm set ambient light 0.05, 0, 0 ` a dull red light
lm set ambient occlusion on 20, 50, 1
` now build the light map
lm build collision data
lm set light map name "myFirstLM"
lm build light maps 512, 0.2, 1
lm reset ` clear the collision data, etc
repeat
text 20, 20, "fps = "+str$(screen fps())
text 20, 40, "fvf = "+str$(fvf)
positionCamera()
sync
until spacekey()
end
function positionCamera()
control camera using arrowkeys 0, 1, 0
cx# = cx# + mousemovey(): cy# = cy# + mousemovex()
rotate camera cx#, cy#, 0
endfunction
There are three main problems:
1. No shadows - or the shadows are all in the centre of the plain.
2. The shading on the spheres doesn't seem to match the light's position - e.g. spheres A and B.
3. Noticeable artefacts on the spheres (you have to run the demo to see these and put the camera in the light's position).
I've compared the above code with the occlusion demo code that comes with Dark Lights and while there are differences I can't see the crucial ones which make the occlusion demo work and mine fail. Here's the demo that comes with Dark Lights:
remstart
*
* Ambient Occlusion
*
* - Shows the ambient occlusion tchnique for global illumination.
* - Contains a single point light but produces a realistic shaded scene.
*
remend
rem render setup
sync on
sync rate 0
set camera range 1,1000
randomize timer()
autocam off
color backdrop 0
set text font "Verdana" : set text size 14
LM Start
rem create a floor and 3 objects and position them in the scene
make object box 1,100,1,100
make object cube 2,10
make object sphere 3,10,30,30
make object cone 4,10
position object 1,0,-0.5,0
position object 2,19,5,3
position object 3,-7,5,-9
position object 4,-16,5,18
rem position the light and a sphere to represent it
posX# = 27
posY# = 33
posZ# = -20
rem the only point light in the scene
LM Add Custom Point Light posX#,posY#,posZ#,500,500,0.000064,0.32,1.0,1.0
make object sphere 10,1
position object 10,posX#,posY#,posZ#
rem set the ambient light colour then set occlusion on with 100 rays of length 20 with a consistent pattern(1).
LM Set Ambient Light 0.4,0.4,0.4
LM Set Ambient Occlusion On 100,20,1
rem add objects as collision objects to cast shadows
LM Add Collision Object 1
LM Add Collision Object 2
LM Add Collision Object 3
LM Add Collision Object 4
LM Build collision Data
rem add objects as light map objects to receive lightmaps
LM Add Light Map Object 1
LM Add Light Map Object 2
LM Add Light Map Object 3
LM Add Light Map Object 4
rem start the light mapping thread
starttimer=timer()
LM Build Light Maps Thread 1024,4.0,1
load dll "Kernel32.dll",1
sync off
rem get current status and display whilst running
while LM Get Complete()=0
rem make DBPro wait before trying again to give the light mapper thread the CPU
call dll 1,"Sleep",100
cls
set cursor 0,0
print LM Get Status( );" ";int(LM Get Percent());"%"
endwhile
sync on
endtimer = timer()
rem light mapping complete remove all collision and light map objects and lights, they are no longer needed.
LM Reset
rem position camera and reset mouse movement
position camera 0,50,-50
point camera 0,0,0
null = mousemovex()
null = mousemovey()
do
if ( keystate(59)=1 and f1Timer<timer() )
f1Timer = timer()+300
F1Pressed=1-F1Pressed
endif
rem display the build time
set cursor 0,0
if F1Pressed=0
center text screen width()/2.0,20,"-- Press F1 For Help --"
else
print "Use Arrows Keys to Move, Hold Shift For Slower Movement"
print
print "FPS: ";screen fps()
print "Build Time: ";(endtimer - starttimer)/1000.0;"s"
endif
rem control the camera speed
if shiftkey()=1 then speed# = 0.2*(60.0/screen fps()) else speed#=2.0*(60.0/screen fps())
rem move and rotate the camera
angy# = camera angle y()
angx# = camera angle x()
if upkey()=1 then move camera speed#
if downkey()=1 then move camera -speed#
xrotate camera 0
if leftkey()=1 then yrotate camera angy#-90 : move camera speed# : yrotate camera angy#
if rightkey()=1 then yrotate camera angy#+90 : move camera speed# : yrotate camera angy#
yrotate camera angy#+mousemovex()/3.0
xrotate camera angx#+mousemovey()/3.0
sync
loop
end