Cool. You can modify that code just a bit for a little speed boost (yet memory loss) by preloading the alphamap image.
sync on : sync rate 0
backdrop on
color backdrop rgb(0,255,0)
load image "texture.bmp", 1, 1
load image "alpha.bmp", 2, 1
load image "alpha2.bmp", 3, 1
make object plain 1, 256, 256
texture object 1, 1
set object transparency 1, 3
do
if spacekey()=1
set_alpha_mapping(1,2,0,255,100)
endif
if returnkey()=1
set_alpha_mapping(1,3,0,255,100)
endif
control camera using arrowkeys 0, .5, .5
sync
loop
function set_alpha_mapping(image,map,min,max,multi)
mem=free_memblock() : make memblock from image mem,image
`map=free_image()
memmap=free_memblock()
`load image map$,map,1
make memblock from image memmap,map
sx=memblock dword(mem,0) : sy=memblock dword(mem,4)
write memblock dword mem,8,32
for x=0 to sx-1
for y=0 to sy-1
pos=(y*sx+x)*4+12
alpha=0
for c=0 to 2 : alpha=alpha+memblock byte(memmap,pos+c) : next c
alpha=alpha/3.0
if alpha<min then alpha=0
if alpha>max then alpha=255
write memblock byte mem,pos+3,(alpha*multi)/100.0
next y
next x
make image from memblock image,mem
delete memblock mem
delete memblock memmap
`delete image map
endfunction
function free_image()
for i=1 to 1024
if image exist(i)=0 then exit
next i
endfunction i
function free_memblock()
for m=1 to 255
if memblock exist(m)=0 then exit
next m
endfunction m
You can even add a save image line inside the function to save your alphamapped image for loading later so save even more time.