Just a quick code snippet to show how the textures are made,it needs Evolved`s cubic shadow shader to work,which is attached.Every time its run it produces a different texture and normal map for the track and landscape.The landscape has its texture heavily scaled so as to only need a small texture and speed up loading times.This is only a quick demonstration and other steps are needed but do take up a bit of time, which is why the whole thing is made up of separate applications so you can change the track layout without having to rebuild textures or vice versa.
A lot of the code used is from the code snippets sections,so if any one spots there code,id like to say thank you.I dont see the point of re-inventing the wheel.
`texture test 2012
`======================
`©P.Parkinson
`======================
`Main Source File
`*********************************
`enviroment set up
IF CHECK DISPLAY MODE(1024,768,32)
SET DISPLAY MODE 1024,768,32
h=DESKTOP HEIGHT()
w=DESKTOP WIDTH()
posx=w/2-512
posy=h/2-384
ELSE
SET DISPLAY MODE 640,480,32
h=DESKTOP HEIGHT()
w=DESKTOP WIDTH()
posx=w/2-320
posy=h/2-240
ENDIF
SET WINDOW POSITION posx,posy
SYNC ON
SYNC RATE 60
AUTOCAM OFF
HIDE MOUSE
SET TEXT FONT "Arial"
SET TEXT SIZE 12
SET TEXT TRANSPARENT
POSITION CAMERA 50,50,-50
POINT CAMERA 0,0,0
POSITION MOUSE SCREEN WIDTH()/2,SCREEN HEIGHT()/2
dummy=MOUSEMOVEX()
dummy=MOUSEMOVEY()
`*********************************
`declarations and setup starts here
`` load fx
load effect "cubicshadowmapping.fx",1,0
``set up camera for shadows
MAKE CAMERA 1
GLOBAL camera_image aS INTEGER
camera_image=free_image()
set camera to image 1,camera_image,512,512
color backdrop 1,rgb(255,255,255)
Make Dynamic Cube Map 1,512
dummy=make vector4(1)
``lighting position
global xpos:global ypos:global zpos
xpos=1000:ypos=4000:zpos=1000
dim temp(4096,4096) as float
GLOBAL texture_size aS integer=256
DIM tex(texture_size,texture_size)
texT 0,0,"Making Crackle Texture"
SYNC
GLOBAL crackle_texture aS INTEGER
crackle_texture=free_image()
make_crackle_texture(crackle_texture)
SAVE IMAGE "crackle.bmp",crackle_texture
``normal map variables
GLOBAL normal_scale aS float:normal_scale= 0.2
GLOBAL normal_y_scale aS float:normal_y_scale=3.0
``*******************************
``land texture and normal maker
CLS
texT 0,0,"Making Landscape Texture"
SYNC
GLOBAL landscape_texture aS integer
landscape_texture=free_image()
make_landscape_texture(landscape_texture)
CLS
texT 0,0,"Making Landscape Normal Texture"
SYNC
GLOBAL landscape_normal_texture aS INTEGER
landscape_normal_texture=free_image()
make_normal_map_texture(landscape_texture,landscape_normal_texture)
SAVE IMAGE "merged.bmp",landscape_texture
SAVE IMAGE "merged_nrm.png",landscape_normal_texture
CLS
MAKE OBJECT CUBE 1,20
texTURE OBJECT 1,landscape_texture
POSITION OBJECT 1,-40,0,0
MAKE OBJECT CUBE 2,20
texTURE OBJECT 2,landscape_normal_texture
POSITION OBJECT 2,40,0,0
MAKE OBJECT CUBE 3,20
texTURE OBJECT 3,0,landscape_texture
texTURE OBJECT 3,1,landscape_normal_texture
aPPLY CUBE MAP TO OBJECT 3,2,1
SET OBJECT EFFECT 3,1
`*********************************
`main loop starts here
update_light(xpos,ypos,zpos,1.0,1.0,1.0,10000)
DO
texT 0,0,"Normal Map Y Scale - "+str$(normal_y_scale)+" Up/Down To Change"
texT 0,20,"Normal Map X/Z Scale - "+str$(normal_scale)+" Left/Right To Change"
text 0,40,"Spacekey To Make Track Texture"
IF UPKEY()
normal_y_scale=normal_y_scale+0.1
make_normal_map_texture(landscape_texture,landscape_normal_texture)
texTURE OBJECT 2,landscape_normal_texture
texTURE OBJECT 3,1,landscape_normal_texture
SAVE IMAGE "merged_nrm.png",landscape_normal_texture
ENDIF
IF DOWNKEY() aND normal_y_scale>0.2
normal_y_scale=normal_y_scale-0.1
make_normal_map_texture(landscape_texture,landscape_normal_texture)
texTURE OBJECT 2,landscape_normal_texture
texTURE OBJECT 3,1,landscape_normal_texture
SAVE IMAGE "merged_nrm.png",landscape_normal_texture
ENDIF
IF rightKEY()
normal_scale=normal_scale+0.001
make_normal_map_texture(landscape_texture,landscape_normal_texture)
texTURE OBJECT 2,landscape_normal_texture
texTURE OBJECT 3,1,landscape_normal_texture
SAVE IMAGE "merged_nrm.png",landscape_normal_texture
ENDIF
IF leftKEY() aND normal_scale>0.002
normal_scale=normal_scale-0.001
make_normal_map_texture(landscape_texture,landscape_normal_texture)
texTURE OBJECT 2,landscape_normal_texture
texTURE OBJECT 3,1,landscape_normal_texture
SAVE IMAGE "merged_nrm.png",landscape_normal_texture
ENDIF
mouse_control(1.0)
SYNC
if spacekey() then exit
LOOP
CLS
SYNC
``clean up
DELETE OBJECT 1
DELETE OBJECT 2
DELETE OBJECT 3
normal_scale= 0.2
normal_y_scale=3.0
`*******************************
``track texture and normal maker
CLS
texT 0,0,"Making Track Texture"
SYNC
GLOBAL track_texture aS integer
track_texture=free_image()
make_track_texture(track_texture)
CLS
texT 0,0,"Making Track Normal Texture"
SYNC
GLOBAL track_normal_texture aS INTEGER
track_normal_texture=free_image()
make_normal_map_texture(track_texture,track_normal_texture)
SAVE IMAGE "track.bmp",track_texture
SAVE IMAGE "track_nrm.png",track_normal_texture
CLS
MAKE OBJECT CUBE 1,20
texTURE OBJECT 1,track_texture
POSITION OBJECT 1,-40,0,0
MAKE OBJECT CUBE 2,20
texTURE OBJECT 2,track_normal_texture
POSITION OBJECT 2,40,0,0
MAKE OBJECT CUBE 3,20
texTURE OBJECT 3,0,track_texture
texTURE OBJECT 3,1,track_normal_texture
aPPLY CUBE MAP TO OBJECT 3,2,1
SET OBJECT EFFECT 3,1
`*********************************
`main loop starts here
update_light(xpos,ypos,zpos,1.0,1.0,1.0,10000)
DO
texT 0,0,"Normal Map Y Scale - "+str$(normal_y_scale)+" Up/Down To Change"
texT 0,20,"Normal Map X/Z Scale - "+str$(normal_scale)+" Left/Right To Change"
IF UPKEY()
normal_y_scale=normal_y_scale+0.1
make_normal_map_texture(track_texture,track_normal_texture)
texTURE OBJECT 2,track_normal_texture
texTURE OBJECT 3,1,track_normal_texture
SAVE IMAGE "track_nrm.png",track_normal_texture
ENDIF
IF DOWNKEY() aND normal_y_scale>0.2
normal_y_scale=normal_y_scale-0.1
make_normal_map_texture(track_texture,track_normal_texture)
texTURE OBJECT 2,track_normal_texture
texTURE OBJECT 3,1,track_normal_texture
SAVE IMAGE "track_nrm.png",track_normal_texture
ENDIF
IF rightKEY()
normal_scale=normal_scale+0.001
make_normal_map_texture(track_texture,track_normal_texture)
texTURE OBJECT 2,track_normal_texture
texTURE OBJECT 3,1,track_normal_texture
SAVE IMAGE "track_nrm.png",track_normal_texture
ENDIF
IF leftKEY() aND normal_scale>0.002
normal_scale=normal_scale-0.001
make_normal_map_texture(track_texture,track_normal_texture)
texTURE OBJECT 2,track_normal_texture
texTURE OBJECT 3,1,track_normal_texture
SAVE IMAGE "track_nrm.png",track_normal_texture
ENDIF
mouse_control(1.0)
SYNC
LOOP
END
`*********************************
`functions start here
FUNCTION mouse_control(speed AS FLOAT)
XROTATE CAMERA CAMERA ANGLE X()+MOUSEMOVEY()
YROTATE CAMERA CAMERA ANGLE Y()+MOUSEMOVEX()
IF MOUSECLICK()=1 THEN MOVE CAMERA speed
IF MOUSECLICK()=2 THEN MOVE CAMERA (0-speed)
dummy=MOUSEMOVEX()
dummy=MOUSEMOVEY()
ENDFUNCTION
function hmap_fractal(size,n#)
`thanks to who ever did this code,had it so long,and it never fails to work for me
av as float
rn as float:rn=n#
s=size ` units and array size; must be a power of 2
dim a(s,s,1) as float
` do the diamond square algorithm
` paying special attention to wrapping around
c=s
repeat
for z=0 to (s-c) step c
for x=0 to (s-c) step c
av=(a(x,z)+a(x+c,z)+a(x,z+c)+a(x+c,z+c))/4.0
av=av+((-50+rnd(100))/rn)
a(x+(c/2),z+(c/2))=av
next x
next z
w=1
for z=0 to (s-(c/2)) step (c/2)
for x=0 to (s-c) step c
x2=x+(w*(c/2))
av=a(x2,z+(c/2))+a(x2+(c/2),z)
if x2=0
av=av+a(s-(c/2),z)
else
av=av+a(x2-(c/2),z)
endif
if z=0
av=av+a(x2,s-(c/2))
else
av=av+a(x2,z-(c/2))
endif
av=av/4.0
av=av+((-50+rnd(100))/rn)
a(x2,z,0)=av
if x2=0 then a(s,z,0)=av
if z=0 then a(x2,s,0)=av
next x
w=1-w
next z
c=c/2
rn=rn*2.0
until c < 2
`find min/max height
minh#=5000:maxh#=-5000
for z=0 to size
for x=0 to size
a(z,x,0)=a(z,x,0)
if a(x,z,0)<minh# then minh#=a(x,z,0)
if a(x,z,0)>maxh# then maxh#=a(x,z,0)
next x
next z
`update data array and raise it up so the lowest point is>=0 and find new max height then set all heights to 0 to 255 range
maxh#=-50000
for z=0 to size
for x=0 to size
av=a(x,z,0)
if minh#<0 then temp(x,z) = av+abs(minh#)
if minh#>=0 then temp(x,z) = av-minh#
if temp(x,z)>maxh# then maxh#=temp(x,z)
next x
next z
if maxh#>255
newh#=255.0/maxh#
for z=0 to size
for x=0 to size
temp(x,z)=temp(x,z)*newh#
next x
next z
endif
ENDFUNCTION
FUNCTION make_crackle_texture(img_num)
IF BITMAP EXIST(1) THEN DELETE BITMAP 1
create bitmap 1,texture_size,texture_size
set current bitmap 1
set image colorkey 0,0,0
ink rgb(255,255,255),0
box 0,0,texture_size,texture_size
FOR l=1 TO 3
hmap_fractal(texture_size,(0.1*l)/0.5)
FOR y=0 TO texture_size
FOR x=0 TO texture_size
IF temp(x,y)>=50 and temp(x,y)<=52
col=(52-temp(x,y))*40
DOT x,y,rgb(col,col,col)
ENDIF
IF temp(x,y)>=100 and temp(x,y)<=102
col=(102-temp(x,y))*40
DOT x,y,rgb(col,col,col)
ENDIF
IF temp(x,y)>=150 and temp(x,y)<=152
col=(152-temp(x,y))*40
DOT x,y,rgb(col,col,col)
ENDIF
NEXT x
NEXT y
NEXT l
GET IMAGE img_num,0,0,texture_size,texture_size
SET CURRENT BITMAP 0
ENDFUNCTION
function make_landscape_texture(image_num)
`sand grass rock
make_sprite(235,180,50,1000):sprite 1,-128,-128,1000:offset sprite 1,64,64
make_sprite(205,128,50,1001):sprite 2,-128,-128,1001:offset sprite 2,64,64
make_sprite(128,50,50,1002):sprite 3,-128,-128,1002:offset sprite 3,64,64
make_sprite(0,200,0,1003):sprite 4,-128,-128,1003:offset sprite 4,64,64
make_sprite(0,128,0,1004):sprite 5,-128,-128,1004:offset sprite 5,64,64
make_sprite(0,50,0,1005):sprite 6,-128,-128,1005:offset sprite 6,64,64
make_sprite(30,30,30,1006):sprite 7,-128,-128,1006:offset sprite 7,64,64
make_sprite(70,70,70,1007):sprite 8,-128,-128,1007:offset sprite 8,64,64
make_sprite(120,120,120,1008):sprite 9,-128,-128,1008:offset sprite 9,64,64
make_sprite(170,170,170,1009):sprite 10,-128,-128,1009:offset sprite 10,64,64
make_sprite(220,220,220,1010):sprite 11,-128,-128,1010:offset SPRITE 10,64,64
make_sand_texture(1011,texture_size)
make_grass_texture(1012,texture_size)
make_rock_texture(1013,texture_size)
hmap_fractal(texture_size,0.1)
`transfer ´temp´ array to ´tex´ array
for z=0 to texture_size
for x=0 to texture_size
tex(x,z)=temp(x,z)
next x
next z
create bitmap 1,texture_size,texture_size
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to texture_size
for x=1 to texture_size
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,255
inc pos
next x
next y
make image from memblock 1014,1
delete memblock 1
hmap_fractal(texture_size,0.1)
`transfer ´temp´ array to ´tex´ array
for z=0 to texture_size
for x=0 to texture_size
tex(x,z)=temp(x,z)
next x
next z
create bitmap 1,texture_size,texture_size
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to texture_size
for x=1 to texture_size
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,255
inc pos
next x
next y
make image from memblock 1015,1
delete memblock 1
blend_images(1011,1012,1014,1016,texture_size,texture_size)
blend_Images(1016,1013,1015,1017,texture_size,texture_size)
blend_images(crackle_texture,1017,crackle_texture,image_num,texture_size,texture_size)
delete image 1011
delete image 1012
delete image 1013
delete image 1014
delete image 1015
DELETE IMAGE 1016
delete image 1017
ENDFUNCTION
FUNCTION make_track_texture(image_num)
`tarmac
make_sprite(30,30,30,1000):sprite 1,-128,-128,1000:offset sprite 1,64,64
make_sprite(40,40,40,1001):sprite 2,-128,-128,1001:offset sprite 2,64,64
make_sprite(50,50,50,1002):sprite 3,-128,-128,1002:offset sprite 3,64,64
make_sprite(70,60,60,1003):sprite 4,-128,-128,1003:offset sprite 4,64,64
make_sprite(80,70,70,1004):sprite 5,-128,-128,1004:offset sprite 5,64,64
make_sprite(90,80,80,1005):sprite 6,-128,-128,1005:offset sprite 6,64,64
make_sprite(100,90,90,1006):sprite 7,-128,-128,1006:offset sprite 7,64,64
make_sprite(110,100,100,1007):sprite 8,-128,-128,1007:offset sprite 8,64,64
make_sprite(120,110,110,1008):sprite 9,-128,-128,1008:offset SPRITE 9,64,64
make_sprite(130,120,120,1009):sprite 10,-128,-128,1009:offset SPRITE 10,64,64
make_sprite(140,130,130,1010):sprite 11,-128,-128,1010:offset SPRITE 10,64,64
make_sand_texture(1011,texture_size)
make_grass_texture(1012,texture_size)
make_rock_texture(1013,texture_size)
hmap_fractal(texture_size,0.1)
`transfer ´temp´ array to ´tex´ array
for z=0 to texture_size
for x=0 to texture_size
tex(x,z)=temp(x,z)
next x
next z
create bitmap 1,texture_size,texture_size
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to texture_size
for x=1 to texture_size
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,255
inc pos
next x
next y
make image from memblock 1014,1
delete memblock 1
hmap_fractal(texture_size,0.1)
`transfer ´temp´ array to ´tex´ array
for z=0 to texture_size
for x=0 to texture_size
tex(x,z)=temp(x,z)
next x
next z
create bitmap 1,texture_size,texture_size
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to texture_size
for x=1 to texture_size
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,255
inc pos
next x
next y
make image from memblock 1015,1
delete memblock 1
blend_images(1011,1012,1014,1016,texture_size,texture_size)
blend_Images(1016,1013,1015,1017,texture_size,texture_size)
blend_Images(crackle_texture,1017,crackle_texture,1018,texture_size,texture_size)
``make stripes
IF BITMAP EXIST(1) THEN DELETE BITMAP 1
create bitmap 1,texture_size,texture_size
set current bitmap 1
SET IMAGE COLORKEY 0,0,0
INK RGB(255,255,255),0
box 0,0,texture_size,texture_size
INK RGB(40,30,30),0
LINE 40,0,40,texture_size
LINE 40,texture_size,50,texture_size
LINE 50,texture_size,50,0
LINE 50,0,40,0
for l=0 to texture_size step texture_size/4
h=l+rnd(5)
if h>texture_size-3 then h=texture_size-3
box 40,h,50,h+3
NEXT l
line texture_size-50,0,texture_size-50,texture_size
LINE texture_size-50,texture_size,texture_size-40,texture_size
LINE texture_size-40,texture_size,texture_size-40,0
LINE texture_size-40,0,texture_size-50,0
FOR l=0 TO texture_size STEP texture_size/4
h=l+rnd(5)
if h>texture_size-3 then h=texture_size-3
box texture_size-50,h,texture_size-40,h+3
NEXT l
ink rgb(255,255,255),0
GET IMAGE 1019,0,0,texture_size,texture_size
blend_images(1019,1018,1019,image_num,texture_size,texture_size)
SET CURRENT BITMAP 0
delete image 1011
delete image 1012
delete image 1013
delete image 1014
delete image 1015
DELETE IMAGE 1016
DELETE IMAGE 1017
DELETE IMAGE 1018
DELETE IMAGE 1019
ENDFUNCTION
function make_sprite(r#,g#,b#,image_num)
if bitmap exist(1) then delete bitmap 1
create bitmap 1,128,128
set current bitmap 1
set image colorkey 0,0,0
for l=1 to 1000
x=rnd(128)
z=rnd(128)
dot x,z,rgb(r#,g#,b#)
next l
for l=1 to 1000
x=rnd(128)
z=rnd(128)
col#=rnd(30)
r2#=r#+col#
if r2#>255 then r2#=255
if r2#<0 then r2#=0
g2#=g#+col#
if g2#>255 then g2#=255
if g2#<0 then g2#=0
b2#=b#+col#
if b2#>255 then b2#=255
if b2#<0 then b2#=0
dot x,z,rgb(r2#,g2#,b2#)
next l
for l=1 to 100
x=rnd(128)
z=rnd(128)
col#=rnd(50)+50
r2#=col#
g2#=col#
b2#=col#
dot x,z,rgb(r2#,g2#,b2#)
next l
get image image_num,0,0,128,128
set current bitmap 0
ENDFUNCTION
function make_sand_texture(img,size)
if bitmap exist(img) then delete bitmap img
create bitmap img,size,size
set current bitmap img
for z=0 to size step 8
for x= 0 to size step 8
num=rnd(100)
if num<33
rotate sprite 1,rnd(90)
paste sprite 1,x,z
endif
if num>=33 and num<66
rotate sprite 2,rnd(90)
paste sprite 2,x,z
endif
if num>=66
rotate sprite 3,rnd(90)
paste sprite 3,x,z
endif
next x
next z
get image img,0,0,size,size
set current bitmap 0
delete bitmap img
endfunction
function make_grass_texture(img,size)
if bitmap exist(img) then delete bitmap img
create bitmap img,size,size
set current bitmap img
for z=0 to size step 8
for x= 0 to size step 8
num=rnd(100)
if num<33
rotate sprite 4,rnd(90)
paste sprite 4,x,z
endif
if num>=33 and num<66
rotate sprite 5,rnd(90)
paste sprite 5,x,z
endif
if num>=66
rotate sprite 6,rnd(90)
paste sprite 6,x,z
endif
next x
next z
get image img,0,0,size,size
set current bitmap 0
delete bitmap img
endfunction
function make_rock_texture(img,size)
if bitmap exist(img) then delete bitmap img
create bitmap img,size,size
set current bitmap img
for z=0 to size step 8
for x= 0 to size step 8
num=rnd(100)
if num<33
rotate sprite 7,rnd(90)
paste sprite 7,x,z
endif
if num>=33 and num<66
rotate sprite 8,rnd(90)
paste sprite 8,x,z
endif
if num>=66
rotate sprite 9,rnd(90)
paste sprite 9,x,z
endif
next x
next z
get image img,0,0,size,size
set current bitmap 0
delete bitmap img
ENDFUNCTION
FUNCTION make_normal_map_texture(img_num,normal_img_num)
IF MEMBLOCK EXIST (1) THEN DELETE MEMBLOCK 1
IF MEMBLOCK EXIST (2) THEN DELETE MEMBLOCK 2
MAKE MEMBLOCK FROM IMAGE 1,img_num // INPUT buffer
make memblock 2,get memblock size(1) // normal buffer
COPY MEMBLOCK 1, 2, 0, 0, 12 // Copy header
width = memblock DWord( 1, 0 )
height = memblock DWord( 1, 4 )
for y = 0 to height - 1
for x = 0 to width - 1
// Find heights at 4 points
xr1 = sampleRed( x - 1, y ,width,height)
xr2 = sampleRed( x + 1, y ,width,height)
yr1 = sampleRed( x, y - 1 ,width,height)
yr2 = sampleRed( x, y + 1 ,width,height)
// Find normal vector
nx# = ( xr1 - xr2 ) * normal_scale
ny# = normal_y_scale
nz# = ( yr1 - yr2 ) * normal_scale
// Normalize vector
scale# = 1.0 / sqrt( nx# * nx# + ny# * ny# + nz# * nz# )
nx# = nx# * scale#
ny# = ny# * scale#
nz# = nz# * scale#
// Write normal
writeRGB( x, y, nx#, nz#, ny# ,width)
next
next
// Output normal buffer
if image exist(normal_img_num) then delete image normal_img_num
make image from memblock normal_img_num,2
ENDFUNCTION
FUNCTION sampleRed( x aS integer, y as INTEGER,width,height )
if x > width - 1 then x = 0
if y > height - 1 then y = 0
if x < 0 then x = width - 1
if y < 0 then y = height - 1
mb = memblock byte( 1, 12 + ( x + y * width ) * 4 )
mb = mb+memblock BYTE( 1, 12 + ( x + y * width ) * 4 +1 )
mb = mb+memblock BYTE( 1, 12 + ( x + y * width ) * 4 +2 )
mb=mb/3
endfunction mb
FUNCTION writeRGB( x aS integer, y as integer, nx#, ny#, nz#,width )
r = int( 127.5 + nx# * 127.5 )
g = int( 127.5 + ny# * 127.5 )
b = int( 127.5 + nz# * 127.5 )
if r > 255 then r = 255
if g > 255 then g = 255
if b > 255 then b = 255
if r < 0 then r = 0
if g < 0 then g = 0
if b < 0 then b = 0
write memblock byte 2, 14 + ( x + y * width ) * 4, r
write memblock byte 2, 13 + ( x + y * width ) * 4, g
write memblock byte 2, 12 + ( x + y * width ) * 4, b
write memblock byte 2, 15 + ( x + y * width ) * 4, 255 // A
endfunction
FUNCTION blend_Images( iUpper, iLower, iAlpha, iResult, Width, Height)
`Dont know the author of this but thanks for great piece of code
Local Percent as float
Local UpperBlue as byte
Local UpperGreen as byte
Local UpperRed as byte
Local LowerBlue as byte
Local LowerGreen as byte
Local LowerRed as byte
Local ResultBlue as byte
Local ResultGreen as byte
Local ResultRed as byte
Local mUpper as integer
Local mLower as integer
Local mAlpha as integer
Local mResult as integer
mUpper = find free memblock(1,10)
mLower = find free memblock(11,10)
mAlpha = find free memblock(21,10)
mResult = find free memblock(31,10)
make memblock from image mUpper,iUpper
make memblock from image mLower,iLower
make memblock from image mAlpha,iAlpha
make memblock from image mResult,iUpper
mbSize = get memblock size(mUpper)
for Pos = 12 to mbSize - 12 step 4
Percent = (memblock byte(mAlpha,Pos)/255.0)
UpperBlue = memblock byte(mUpper,Pos+0)
UpperGreen = memblock byte(mUpper,Pos+1)
UpperRed = memblock byte(mUpper,Pos+2)
LowerBlue = memblock byte(mLower,Pos+0)
LowerGreen = memblock byte(mLower,Pos+1)
LowerRed = memblock byte(mLower,Pos+2)
ResultBlue = UpperBlue*(1-Percent)+LowerBlue*Percent
ResultGreen = UpperGreen*(1-Percent)+LowerGreen*Percent
ResultRed = UpperRed*(1-Percent)+LowerRed*Percent
write memblock byte mResult,Pos+0,ResultBlue
write memblock byte mResult,Pos+1,ResultGreen
write memblock byte mResult,Pos+2,ResultRed
write memblock byte mResult,Pos+3,255
next Pos
make image from memblock iResult, mResult
delete memblock mUpper
delete memblock mLower
delete memblock mAlpha
delete memblock mResult
ENDFUNCTION
function free_object()
repeat
inc i
if object exist(i)=0 then found=1
until found
endfunction i
function free_image()
repeat
inc i
if image exist(i)=0 then found=1
until found
ENDFUNCTION i
function update_light(xpos#,ypos#,zpos#,r#,g#,b#,range#)
set vector4 1,xpos#,ypos#,zpos#,0
set effect constant vector 1,"LightPosition",1
set vector4 1,r#,g#,b#,0
set effect constant vector 1,"LightColor",1
set effect constant float 1,"LightRange",range#
``Render shadiow map
set effect technique 1,"DepthMap"
Render Dynamic Cube Map 1,1,xpos#,ypos#,zpos#
``Main Scene
set effect technique 1,"ShadowMapping"
sync mask 2^0
endfunction