Hello!
I know there's a few threads out there on this but none of them have the solution I'm looking for (must be Murphy's law again...), so here it is:
I'm using a shader from GreenGandalf that I've tried to modify to take a lightmap as well. The problem is that when the shader is applied the object seems to loose it's lightmapped UV coords.
Here's the example (you'll need darklights to compile it):
remstart
*
* Quality
*
* - Shows how different qualtiies effect the appearance of the final scene
*
remend
rem set the light map quality here,
Quality# = 4.0
MaxObjects=20
VIEW_ONLY = 0
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
//COMMENT THIS OUT WHEN YOU ARE CREATING LIGHTMAPS,
//ONCE THEY'RE CREATED YOU CAN UNCOMMENT THIS TO VIEW THE RESULT WITH THE SHADER APPLIED
GOTO VIEW
LM Start
rem make a floor and a sphere to cast a shadow onto it
make object box 1,200,1,200
position object 1,0,-0.5,0
load object "building21.dbo",MaxObjects+1
load image "building21_d.dds",1
texture object MaxObjects+1,0,1
for t=2 to MaxObjects
clone object t,MaxObjects+1
position object t,-100+(11*t),0,-100+(11*t)
yrotate object t,0
next t
delete object MaxObjects+1
rem add level as collision objects to cast shadows
for t=1 to MaxObjects
LM Add Collision Object t
next t
LM Build collision Data
rem add level as a light map object to receive lightmaps
for t=1 to MaxObjects
LM Add Light Map Object t
next t
LM Add Point Light 30,30,-20,300,1.0,0.6,0.7
make object sphere 101,1
position object 101,30,30,-20
LM Add Point Light -20,40,50,300,0.4,0.9,0.6
make object sphere 102,1
position object 102,-20,40,50
LM Add Point Light -30,30,-30,300,1.0,1.0,0.6
make object sphere 103,1
position object 103,-30,30,-30
if VIEW_ONLY=0
rem start the light mapping thread
starttimer=timer()
LM Build Light Maps Thread 2048,Quality#,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
call dll 1,"Sleep",100
cls
set cursor 0,0
print LM Get Status( );" ";int(LM Get Percent());"%"
endwhile
sync on
endtimer = timer()
endif
rem light mapping complete remove all collision and light map objects and lights.
LM Reset
RETURNTOLOOP:
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 "Quality: ";Quality#
print "Build Time: ";(endtimer - starttimer)/1000.0;"s"
endif
rem control the speed of the camera
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
if spacekey()=1
for t=1 to MaxObjects
if file exist("LM_OBJ"+str$(t)+".dbo")=1 then delete file "LM_OBJ"+str$(t)+".dbo"
save object "LM_OBJ"+str$(t)+".dbo",t
next t
end
endif
sync
loop
VIEW:
`load image "lm.png",2
`load image "building21_d.dds",2
load image "building21_n.dds",3
load effect "GGbump06.fx",1,0
`null=make vector4(1)
`set vector4 1,0,20,0,200
`set effect constant vector 1,"LightPosition ",1
`set vector4 1,1.0,1.0,1.0,1.0
`set effect constant vector 1,"LightColor ",1
for t=1 to MaxObjects
load object "LM_OBJ"+str$(t)+".dbo",t
if t>1
position object t,-100+(11*t),0,-100+(11*t)
yrotate object t,0
`texture object t,0,1
`texture object t,1,2
texture object t,2,3
set object effect t,1
endif
next t
set effect technique 1,"t0"
make object cube MaxObjects+1,2
position object MaxObjects+1,0,20,0
GOTO RETURNTOLOOP
end
I think the easiest solution would be to bake the light map into the diff texture, is there anyway that can be done with darklights?
But I'd rather do it 'properly' with a shader like this one!
Thanks,
BC