Quote: "Also, while Set Ambient no longer works with objects, it no longer works with matrices either."
This is incorrect. It has a more direct effect on matrices. It still affects objects as well. Part of the trick, is positioning the default light 0. It is set as a directional light by default(you can change this if you want) so positioning it is very important to attaining good lighting. Check out the following example. Press space to switch the lighting. Rotate camera with mouse, move with arrow keys.
remstart
==============================================================
= Title : Matrix Normal Shadows using DBC 1.20
= Author : latch
= Date : 11/25/2007
= Update :
= Version:
==============================================================
Comments Example on how to manage shadows using normals
in DBC 1.20 .
The global ambient lighting will affect the matrix
so treat it the same as for set object ambient.
==============================================================
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 800,600,32
sync on
sync rate 60
hide mouse
rem =============================================================
rem = MAIN
rem =============================================================
gosub _init
ink rgb(255,255,255),0
do
gosub _move_camera
text 0,0,"Press Space to toggle ambient lighting control"
if spacekey()=1
amb=1-amb
repeat
rem wait for space release
sync
until spacekey()=0
endif
if amb=1
text 0,20,"Ambient settings lowered"
gosub _lower_ambient
endif
if amb=0
text 0,20,"Ambient settings raised"
gosub _raise_ambient
endif
sync
loop
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_init:
gosub _grass
gosub _land
return
`----------------------------------------------------------------
_grass:
grass=1
CLS RGB(0,20,0)
For N=1 To 10000
Ink RGB(Rnd(15),Rnd(60)+20,Rnd(5)),0
Dot Rnd(129),Rnd(129)
Next N
blur bitmap 0,2
get image grass,0,0,129,129
sync
return
`-----------------------------------------------------------------
_land:
rem create a bumpy matrix with lots of polys so we can see
rem the effects of normals and lighting better
make matrix 1,1000,1000,60,60
prepare matrix texture 1,grass,1,1
randomize matrix 1,30
update matrix 1
rem recalulate mat normals
calc_mat_normals(1,60,60,20.0,20.0)
position camera 500,100,-100
point camera 500,0,500
rem stick an object on the land
make object sphere 1,100
position object 1,500,50,500
return
`----------------------------------------------------------------
_move_camera:
yang#=wrapvalue(yang#+mousemovex())
xang#=wrapvalue(xang#+mousemovey())
rotate camera xang#,yang#,0
if upkey()=1 then move camera 3
if downkey()=1 then move camera -3
return
`----------------------------------------------------------------
_lower_ambient:
set ambient light 50
color ambient light rgb(128,128,128)
set directional light 0,1,-.5,.5
return
`----------------------------------------------------------------
_raise_ambient:
set ambient light 100
color ambient light rgb(255,255,255)
set directional light 0,0,1,1
return
rem =============================================================
rem = FUNCTIONS
rem =============================================================
Function calc_mat_normals(mat,tilex,tilez,sizex#,sizez#)
Rem By Lee Bamber From DB Example - Adds shaded areas to matrix to give depth
rem added tile and tile size factor for normal depth adjustment - latch
for z=1 to tilez
for x=1 to tilex
rem Get matrix heights
h8#=get matrix height(mat,x,z-1)
h4#=get matrix height(mat,x-1,z)
h#=get matrix height(mat,x,z)
h2#=get matrix height(mat,x,z)
rem Calculate projected angle X using heights
x1#=(x-1)*sizex# : y1#=h#
x2#=(x+0)*sizex# : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
z1#=(z-1)*sizez# : y1#=h2#
z2#=(z+0)*sizez# : y2#=h8#
dz#=z2#-z1#
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem Make normal from projected angle
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
rem Setting matrix normal for smoothness
set matrix normal mat,x,z,nx#,ny#,nz#
next x
next z
update matrix mat
EndFunction
`----------------------------------------------------------------
rem =============================================================
rem = DATA STATEMENTS
rem =============================================================
I still have trouble getting it right. Even after I wrote the example above, I ran into problems with lighting in old code that I couldn't figure out. Check out this link:
http://forum.thegamecreators.com/?m=forum_view&t=120846&b=10
Enjoy your day.