Hawkblood:
I think the problem is the combination of the rigged/animated character combined with the contents of my game. Because when I use the character with bone and animations in an empty world, the shadows work fine, if not perfectly. It's only when I do it in my current game that it lags.
I can make a simple code, but it will probably work fine since it won't contain the contents of my game in it. I'm not trying to sound stubborn about posting an example code, mind you.
Green Gandalf:
Yeah that's the problem I'm having.
Annyways. If this helps, here is Green Gandalf's code except I placed my character in it (attached). As you can see, it works fine with no lag (this character has bones and animations), which I think is because it is an empty world.
set display mode desktop width(), desktop height(), 32
sync on : sync rate 60 : autocam off
` Spooky's original demo with minor additions and changes by Green Gandalf
` press s to turn shadows on, n to turn them off
` 0 = use cpu (slow and inaccurate), 1 = gpu shader (fast and accurate)
shader=1
shadow = 1
` make a texture
ink rgb(255,0,0),0
box 0,0,16,16
get image 1,0,0,16,16
` hide main light
hide light 0
set ambient light 30
` make ground
make matrix 1,1000,1000,64,64
prepare matrix texture 1,1,1,1
position matrix 1,-250,0,-250
` make some objects to cast shadows
o=1
for f=0 to 340 step 20
inc o
make object box o,5,40,5
texture object o,1
set shadow shading on o,-1,1000,shader
` object, mesh, range, shader
` object=quite obvious really
` mesh=-1 means use objects mesh, but gives option of using lower res mesh
` range=how far to cast shadow - useful as shadows cast on multiple objects through solid objects. Grrrrr
` shader=0=cpu,1=gpu
position object o,100*sin(f),20,100*cos(f)
next f
` place some high poly objects
remstart
make object sphere o, 10
scale object o, 100, 500, 100
position object o, 0, 25, 0
set shadow shading on o, -1, 1000, shader
remend
` place my character
inc o
load object "boy.x", o
scale object o, 500, 500, 500
position object o, 0, 0, 0
set shadow shading on o, -1, 1000, shader
` make light object to show where light is
inc o
make object sphere o,-10
` make new light and set shadow position
make light 1
set point light 1,0,0,0
set light range 1,1000
lightmode=1
` set shadow mode to 'light' mode,ie shadows will be cast from selected light number
` in this case is 1 (x, y and z values will be ignored)
` you can also use value of -1 which means you can force position of shadows
set shadow position lightmode,0,0,0
position camera -20,8,-150
point camera 0,0,0
ink rgb(255,255,255),0
a#=0
repeat
key$ = inkey$()
if key$ = "s" and shadow = 0
shadow = 1
for o = 2 to 20
set shadow shading on o,-1,1000,shader
next o
else
if key$ = "n" and shadow = 1
shadow = 0
for o = 2 to 20
set shadow shading off o
next o
endif
endif
control camera using arrowkeys 0,2,2
gosub movelight
text 0,0,"cursors to move around, s/n for shadows/no shadows"
text 0,20,"FPS="+str$(screen fps())
sync
until spacekey()
end
movelight:
a#=wrapvalue(a#+0.2)
x#=newxvalue(0,a#,150)
y#=50+(50.0*sin(a#*2.0))
z#=newzvalue(0,a#,150)
position light 1,x#,y#,z#
position object o,x#,y#,z#
return
I think it's something else in the world combining with my character that is making it lag.