Code:
Rem Project: DarkRPG
Rem Created: Friday, June 29, 2012
Rem ***** Main Source File *****
Sync On : Sync Rate 60 : Sync
Set Display Mode Desktop Width(), Desktop Height(), 32
Center Text Screen Width()/2, Screen Height()/2, "Please Wait, loading assets..." : Sync : Cls
SetDefaults()
mapCount = 0
Open To Read 1, "Maps.dat"
Read String 1, Count$
dim maps(val(Count$)) as Map
Read String 1, maps(0).Name
Close File 1
set camera range 1,10000
Fog On : Fog Distance 1000, 5000
LoadTerrain(0)
Bt Enableautorender 1
Position Camera 0, 0, 0
Do
Control Camera Using Arrowkeys 0, 10, 2
Position Camera Camera Position X(), Bt Getgroundheight(maps(0).ID, Camera Position X(), Camera Position Z()) + 40, Camera Position Z()
`UpDateWater()
text 10,10,str$(screen fps())
text 10,25,str$(Camera Position X())
text 10,40,str$(Camera Position Z())
`text 10,55,str$(Object Size X(maps(terrainId).ObjID))
Sync
Loop
Rem ***** Included Source File *****
Global ImgID
Global ObjID
Global INIID
Global FxID
Function SetDefaults()
ImgID = 1
ObjID = 1
INIID = 1
FxID = 1
Endfunction
Function GetImgID()
ImgIDSend = ImgID
ImgID = ImgID + 1
Endfunction ImgIDSend
Function GetObjID()
ObjIDSend = ObjID
ObjID = ObjID + 1
Endfunction ObjIDSend
Function GetINIID()
INIIDSend = INIID
INIID = INIID + 1
Endfunction InIIDSend
Function GetFxID()
FxIDSend = FxID
FxID = FxID + 1
Endfunction FxIDSend
Rem ***** Included Source File *****
Type Map
ID as integer
Name as string
hmid as integer
txid as integer
dtid as integer
ObjID as integer
IniID as integer
WaterID as Integer
WaterShaderID as integer
WaterImg1 as integer
WaterImg2 as integer
WaterImg3 as integer
WaterImg4 as integer
WaterImg5 as Integer
EndType
Function LoadTerrain(terrainId)
maps(terrainId).IniID = GetINIID()
Make Lookup from INI maps(terrainId).IniID, "Media\Maps\" + maps(terrainId).name + ".dat"
HMPath$ = "Media\Maps\" + maps(terrainId).Name + "\heightmap.bmp"
TXPath$ = "Media\Maps\" + maps(terrainId).Name + "\texture.bmp"
if val(lookup$(maps(terrainId).IniID, "detail/enable"))
DTPath$ = "Media\Maps\" + maps(terrainId).Name + "\detail.bmp"
endif
maps(terrainId).hmid = GetImgID()
maps(terrainId).txid = GetImgID()
maps(terrainId).dtid = GetImgID()
Load Image HMPath$, maps(terrainId).hmid
Load Image TXPath$, maps(terrainId).txid
if val(lookup$(maps(terrainId).IniID, "detail/enable"))
Load Image DTPath$, maps(terrainId).dtid
endif
maps(terrainId).ID = Bt Maketerrain()
Bt Setterrainheightmap maps(terrainId).ID, maps(terrainId).hmid
Bt Setterraintexture maps(terrainId).ID, maps(terrainId).txid
if val(lookup$(maps(terrainId).IniID, "detail/enable"))
Bt Setterraindetail maps(terrainId).ID, maps(terrainId).dtid
endif
Bt Setterrainscale maps(terrainId).ID, val(lookup$(maps(terrainId).IniID, "scale/size"))
Bt Setterrainyscale maps(terrainId).ID, val(lookup$(maps(terrainId).IniID, "scale/height"))
Bt Setterrainsplit maps(terrainId).ID, 8
if val(lookup$(maps(terrainId).IniID, "detail/enable"))
Bt Setterraindetailtile maps(terrainId).ID, val(lookup$(maps(terrainId).IniID, "detail/tile"))
endif
Bt Setterrainlod maps(terrainId).ID, 4
Bt Setterrainloddistance maps(terrainId).ID, 1, 1250.0
Bt Setterrainloddistance maps(terrainId).ID, 2, 2500.0
Bt Setterrainloddistance maps(terrainId).ID, 3, 3750.0
maps(terrainId).ObjID = GetObjID()
Bt Setterrainsmoothing maps(terrainId).ID, 4
Bt Buildterrain maps(terrainId).ID, maps(terrainId).ObjID, 1
if val(lookup$(maps(terrainId).IniID, "water/enable"))
maps(terrainId).WaterID = GetOBJID()
maps(terrainId).WaterImg1 = GetImgID()
maps(terrainId).WaterImg2 = GetImgID()
maps(terrainId).WaterImg3 = GetImgID()
maps(terrainId).WaterImg4 = GetImgID()
maps(terrainId).WaterImg5 = GetImgID()
maps(terrainId).WaterShaderID = GetFXID()
Make Object Plane 1000, 10000, 10000
Xrotate Object 1000, 270
`MakeWater(maps(terrainId).WaterID, maps(terrainId).WaterShaderID, maps(terrainId).WaterImg1, 512, val(lookup$(maps(terrainId).IniID, "water/height")))
Position Object 1000, 0, val(lookup$(maps(terrainId).IniID, "water/height"))-1, 0
Endif
Endfunction
function MakeWater(Obj,Shader,Img,ImgSize,Height#)
`Globals
global WaterObj=Obj
global WaterHeight#=Height#
global Fx=Shader
`Setup Cameras
Sw#=screen width():Sh#=screen height()
for c=1 to 2
make camera c
set camera range c,1,15000
set camera aspect c,Sw#/Sh#
backdrop off c
set camera to image c,Img+(c-1),ImgSize,ImgSize
set camera fov c,85
next c
`Make Water plain
load image "Media/FX/Water/Waves.dds",Img+2
load image "Media/FX/Water/Fresnel.bmp",Img+3
load image "Media/FX/Water/WaterMask.bmp",Img+4
make object plain WaterObj,50000,50000
texture object WaterObj,0,Img
texture object WaterObj,1,Img+1
texture object WaterObj,2,Img+2
texture object WaterObj,3,Img+3
texture object WaterObj,4,Img+4
xrotate object WaterObj,270
load effect "Media/FX/Water/Water.fx",Fx,0, 1
set object effect WaterObj,Fx
set object transparency WaterObj,1
endfunction
//--------------
` Update Water
//--------------
function UpDateWater()
`UpDate Water plain
position object WaterObj,object position x(WaterObj),WaterHeight#,object position z(WaterObj)
Hide object WaterObj
`Upade Refract/Reflect cameras
set effect technique Fx,"Refract"
UpDateRefraction()
if camera position y()>WaterHeight#
set effect technique Fx,"ReflectRefract"
UpDateReflection()
else
fog on:fog color rgb(55,65,75)
fog distance 300
endif
`Show Water
show object WaterObj
sync mask 2^0
endfunction
//--------------
` Refraction Update
//--------------
function UpDateRefraction()
position camera 1,camera position x(),camera position y(),camera position z()
rotate camera 1,camera angle x(),camera angle y(),camera angle z()
if camera position y()>WaterHeight#
set camera clip 1,1,0,WaterHeight#+30,0,0,-1,0
fog on:fog color rgb(55,65,75)
fog distance 250+(camera position y()-WaterHeight#)*10
else
set camera clip 1,1,0,WaterHeight#-30,0,0,1,0
fog off
endif
set camera clip 2,0,0,0,0,0,0,0
sync mask 2^1
fastsync
fog off
endfunction
//--------------
` Reflection Update
//--------------
function UpDateReflection()
position camera 2,camera position x(),WaterHeight#-(camera position y()-WaterHeight#),camera position z()
rotate camera 2,-camera angle x(),camera angle y(),camera angle z()
set camera clip 1,0,0,0,0,0,0,0
set camera clip 2,1,0,WaterHeight#-15,0,0,1,0
sync mask 2^2
fastsync
endfunction
Rem ***** Included Source File *****
Video showing the issue:
http://www.youtube.com/watch?v=bCmijSBCMZ8&feature=plcp
Sorry about background noise, I live in a dorm with noisy people.
Also, the software I used to edit and encode the video did a real bad job at it, so the video may look bad... I will find a way around that soon.
Attached is a zip including all files.