Here's a new version of the demo. Most of the options work as intended now.
I've added two new options so there are now 6 options altogether. I've also attached a copy of the media files so you can run my code and see what's happening.
I think option 1 is the main option you need.
set display mode desktop width(), desktop height(), 32
sync on: sync rate 60: sync
load object "myThirdLMObject.dbo", 1
` note: main texture is applied to stage 0 and lightmap to stage 1
` now load images and apply manually using blend mapping
load image "Polyphant01 TM Seamless v2.png", 1 ` main texture
load image "lightmaps/myThirdLM0.png", 2 ` lightmap
set object light 1, 1 ` turn standard lighting calculations on for this object (these are set to OFF for lightmapped objects by default)
set object specular power 1, 40
set object ambient 1, 0 ` turn off ambient light as this should be in the lightmap already
hide light 0 ` because I can't seem to adjust it properly :(
make light 1 ` use this for the dynamic lighting
` change light 1 to a blue point light
set point light 1, 200, 50, 200
set light range 1, 2000
color light 1, rgb(0, 0, 255)
autocam off
position camera 0, 500, 0
point camera 0, 0, 0
global cx#
global cy#
cx# = camera angle x()
cy# = camera angle y()
angle# = 0.0
repeat
text 20, 20, "fps = "+str$(screen fps())
text 20, 40, "object size x = " + str$(object size x(1,1), 0)
center text screen width()/2, 70, text$
key$ = inkey$()
inc angle#, 0.5
select key$
case "1"
` turn on dynamic lighting
` an issue here is which light does the SET OBJECT SPECULAR command refer to?
color light 1, 0, 0, 255
` ** do not know why next two lines do not work **
` set blend mapping on 1, 0, 2, 11, 7 ` this simply adds the lightmap value to the initial dynamic lighting calculated by DBPro
` to get the combined lighting - but final result loks wrong :(
` set blend mapping on 1, 1, 1, 10, 4 ` blends the lighting value calculated from blend stage 0 with the main texture
` the following three lines do work as intended
set blend mapping on 1, 0, 0, 11, 3 ` this simply copies the diffuse lighting without modification
set blend mapping on 1, 1, 2, 11, 7 ` this adds the lightmap value to the dynamic lighting value from stage 0
set blend mapping on 1, 2, 1, 10, 4 ` this blends the final lighting value with the main texture
set object specular 1, rgb(0, 0, 255) ` this is not applied via blending stages
text$ = "combined lightmap and dynamic lighting including specular (seems OK - but why are three blending stages needed?)"
endcase
case "2"
` lightmap only - no texture or dynamic lighting
set blend mapping on 1, 0, 2, 11, 2 ` this simply uses a lightmap value for the combined lighting
set blend mapping on 1, 1, 0, 10, 4 ` blends the lighting value with black lighting
set blend mapping on 1, 2, 0, 10, 3 ` just copies result of stage 1 (to avoid accidental carry over from other options)
set object specular 1, rgb(0, 0, 0)
text$ = "lightmap only (this case works as expected)"
endcase
case "3"
` dynamic diffuse lighting only - no textures, lightmap or specular
` note that in next two lines image ids are set to zero as they are not used
color light 1, 0, 0, 255
set blend mapping on 1, 0, 0, 11, 3 ` this simply copies the diffuse lighting without modification
set blend mapping on 1, 1, 0, 10, 3 ` ditto
set blend mapping on 1, 2, 0, 10, 3 ` just copies result of stage 1 (to avoid accidental carry over from other options)
set object specular 1, rgb(0, 0, 0) ` this is not applied via blending stages
text$ = "dynamic diffuse lighting only - no textures, lightmap or specular (seems OK)"
endcase
case "4"
` specular lighting only - no textures, so you ""should"" only see specular (not quite right yet :( )
` note that in next two lines image ids are set to zero so they default to black
color light 1, 0, 0, 0
set blend mapping on 1, 0, 0, 11, 2 ` disable this stage - i.e. no diffuse lighting
set blend mapping on 1, 1, 0, 10, 2 ` disable this stage - i.e. no texture used
set blend mapping on 1, 2, 0, 10, 3 ` just copies result of stage 1 (to avoid accidental carry over from other options)
set object specular 1, rgb(0, 255, 0) ` this is not applied via blending stages - used green here to make it clear
text$ = "specular lighting only (seems OK - except why isn't light movement smooth?)"
endcase
case "5"
` dynamic diffuse lighting plus textures only - no lightmap or specular
color light 1, 0, 0, 255
set blend mapping on 1, 0, 0, 11, 3 ` this simply copies the diffuse lighting without modification
set blend mapping on 1, 1, 1, 10, 4 ` blends the lighting value calculated from blend stage 0 with the main texture
set blend mapping on 1, 2, 0, 10, 3 ` just copies result of stage 1 (to avoid accidental carry over from other options)
set object specular 1, rgb(0, 0, 0) ` turned off by setting it to black
text$ = "dynamic diffuse lighting plus textures only - no lightmap or specular (seems OK)"
endcase
case "6"
` dynamic diffuse lighting plus lightmap only - no textures or specular
color light 1, 0, 0, 255
set blend mapping on 1, 0, 0, 11, 3 ` this simply copies the diffuse lighting without modification
set blend mapping on 1, 1, 2, 11, 7 ` this adds the lightmap value to the dynamic lighting value from stage 0
set blend mapping on 1, 2, 0, 10, 3 ` just copies result of stage 1 (to avoid accidental carry over from other options)
set object specular 1, rgb(0, 0, 0) ` this is not applied via blending stages
text$ = "dynamic diffuse lighting plus lightmap only - no textures or specular (seems OK)"
endcase
case default
` lightmap and texture only - no dynamic lighting
color light 1, 0, 0, 0 ` turn off light just in case :)
set blend mapping on 1, 0, 2, 11, 2 ` this simply uses a lightmap value for the combined lighting
set blend mapping on 1, 1, 1, 10, 4 ` blends the lighting value with the main texture
set blend mapping on 1, 2, 0, 10, 3 ` just copies result of stage 1 (to avoid accidental carry over from other options)
set object specular 1, rgb(0, 0, 0)
text$ = "lightmap and textures only - no dynamic lighting or specular (seems OK)"
endcase
endselect
position light 1, 200 * cos(angle#), 50, 200 * sin(angle#)
positionCamera()
sync
until spacekey()
end
function positionCamera()
control camera using arrowkeys 0, 1, 0
cx# = cx# + 0.2 * mousemovey(): cy# = cy# + 0.2 * mousemovex()
rotate camera cx#, cy#, 0
endfunction