well I have been working on this for about 2 weeks now off and on a few hours a night
before I get started let me just say I am glad to give some code back to the DBP community and I hope everyone enjoys it.
the star overlay is not broke it works the way I want it to for my game if you wish to change it you will need to mess with the shader
code to much stuff to talk about just download it and mess with it.
Rem Project: DarkCLOUDSample
Rem Created: Sunday, June 28, 2009
// =============================================================
// DarkClouds reflection , refraction , ambient light with stars
// Created by Douglas Hood -=(EDGECOM)=-
// http://www.edgegraphics.biz
// This code / demo can be used for commercial and noncommercial use
// give me a shout out in your credits if you like.
// =============================================================
rem Please wait
set text font "verdana" : s$="generating clouds...please wait"
center text screen width()/2,screen height()/2,s$ : sync
autocam off : color backdrop RGB(0,0,0)
load image "sky\sunFlare.png",10
load image "sky\Moon.png",11
load image "sky\earth.png",12
load image "sky\neptune.png",13
load image "sky\saturn.jpg",14
load image "sky\Rain.jpg",15
load image "sky\Cirrus.jpg",21
//load image "sky\stars.bmp",22
load image "sky\starcolors.bmp",23
load effect "sky\DC_Sky.fx",1,1
GLOBAL ASPECT AS DOUBLE FLOAT : ASPECT = (screen width()+0.0)/(screen height()+0.0)
GLOBAL FOV AS FLOAT : FOV = 61.9621391296
GLOBAL FOV_V AS FLOAT : FOV_V = FOV
GLOBAL FOV_H AS FLOAT : FOV_H = FOV*ASPECT
GLOBAL SKY_WIDTH AS INTEGER : SKY_WIDTH = INT(FOV_H*140.0)
GLOBAL SKY_HEIGHT AS INTEGER : SKY_HEIGHT = INT((FOV_V*120.0)-1000.0)
rem starting at 6am
global time as float : time = 23.9
rem star globals
GLOBAL galaxy_image as integer : galaxy_image = 22
GLOBAL stars_large as integer : stars_large = rnd(60)
GLOBAL stars_small as integer : stars_small = screen width()+screen height()/2
GLOBAL star_res_x as integer : star_res_x = 1024
GLOBAL star_res_y as integer : star_res_y = 1024
GLOBAL comets as integer : comets = rnd(50)
rem call this before making the sky its faster
make_stars()
set text font "verdana" : s$="generating clouds...please wait"
center text screen width()/2,screen height()/2,s$ : sync
set camera range 0,1,FOV_H*FOV_V
rem init app at 60fps
sync on : sync rate 60
rem half-fill the sky with clouds
dc set cloudy 0.1
rem add a high-altitude cloud layer
dc set cirrus clouds 0.1
dc set cirrus image 21
rem clouds at 3 km
dc set cloud height 8
rem set sky brightness to 1
dc set brightness 1.0
rem adjust brightness based on time of day
dc set auto brightness 1
rem set wind to 30 mph at 270 degrees (heading west)
dc set wind 30,270
rem init with texture number 1, and number of keyframes per hour
dc init 1,5
rem modify rayleigh scattering(optional) default: 7,11,24
dc set scattering 7,11,24
rem a slightly yellow sun:
rem DWORD R:255 G:255 B:204
dc set sun color 1.0,1.0,0.8
rem the update command creates the cloud texture
dc update time
rem show texture 1 as the backdrop
GLOBAL SKY_ID AS INTEGER : SKY_ID = 3
make object plain SKY_ID,SKY_WIDTH,SKY_HEIGHT
rotate object SKY_ID,0,180,0
//make object sphere SKY_ID,-(SKY_HEIGHT+SKY_WIDTH),FOV,FOV
//rotate object SKY_ID,180,180,0
fix object pivot SKY_ID
texture object SKY_ID,0,galaxy_image
texture object SKY_ID,1,23
texture object SKY_ID,2,1
set object light SKY_ID,0
SET OBJECT AMBIENT SKY_ID,0
SET OBJECT DIFFUSE SKY_ID, RGB(192,192,192),1
set object effect SKY_ID,1
rem draw the sun
dc set sun image 10,0.2
rem draw the moon - three times!
dc set planet image 1,11,0.2,1
dc set planet direction 1,0.0,0.2,1.0
dc set planet image 2,12,0.4,1
dc set planet direction 2,0.9,0.4,-0.5
dc set planet image 3,13,0.1,1
dc set planet direction 3,0.9,0.4,0.5
dc set planet image 4,14,0.4,1
dc set planet direction 3,0.2,0.4,-0.5
rem create rain (rain will only appear when clouds are heavy)
dc set rain 1,1
dc set rain image 15
rem place camera for best view
SET AMBIENT LIGHT 100
COLOR AMBIENT LIGHT RGB(64,64,128)
SET EFFECT CONSTANT FLOAT 1,"SkyOverlay",1.0
set text font "verdana" : s$="generating terrain...please wait"
center text screen width()/2,screen height()/2,s$ : sync
rem Make terrain
load image "terrain\texture.bmp", 24
load image "terrain\detail.tga", 25
make object terrain 1
set terrain heightmap 1, "terrain\map.bmp"
set terrain scale 1,19.535, 3.5,19.535
set terrain split 1, 16
set terrain tiling 1, 4
set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5
set terrain texture 1, 24,25
build terrain 1
position object 1,-2500,0,-2500
set text font "verdana" : s$="generating water...please wait use 1 to skip the time ahead 4hr and the 2 key to go back an hour.."
center text screen width()/2,screen height()/2,s$ : sync
rem Make Water(Objnum , Fxnum ,Imgnum ,Imgsize, Water Height)
MakeWater(500,500,500,512,95,FOV_H*FOV_V)
set current camera 0
position camera 0,170,283,124
rotate camera 0,350.0,1,0
SET NORMALIZATION ON
rem Main loop
do
rem the 1 key
if KEYSTATE(2)=1
time = time+4.0
if time > 24 then time = 0
wait 10
endif
rem the 2 key
if KEYSTATE(3)=1
time = time-1.0
if time > 24 then time = 0
wait 10
endif
`Control Camera
cr#=0:cf#=0
if rightkey()=1 or KEYSTATE(32)=1 then cr#=-5
if leftkey()=1 or KEYSTATE(30)=1 then cr#=5
if upkey()=1 or KEYSTATE(17)=1 then cf#=5
if downkey()=1 or KEYSTATE(31)=1 then cf#=-5
ncr#=curvevalue(cr#,ncr#,5)
ncf#=curvevalue(cf#,ncf#,5)
cx#=cx#+mousemovey()*0.02
cy#=cy#+mousemovex()*0.02
if cx#>80 then cx#=80
if cx#<-80 then cx#=-80
ncx#=curveangle(cx#,ncx#,2)
ncy#=curveangle(cy#,ncy#,2)
move camera ncf#
rotate camera 0,wrapvalue(ncy#-90),0
move camera ncr#
rotate camera 0,wrapvalue(ncy#+90),0
rotate camera ncx#,ncy#,0
if camera position y()<get terrain ground height(1,camera position x(),camera position z())+25
position camera camera position x(),get terrain ground height(1,camera position x(),camera position z())+25,camera position z()
endif
position object SKY_ID,camera position x(),camera position y(),camera position z()
rotate object SKY_ID,camera angle x(),camera angle y(),camera angle z()
move object SKY_ID,(FOV_H*FOV_V)-FOV
time=time+20.0/(24.0*60.0*60.0)
if time > 23.9
time = 0.0
rem creats a random star / galaxy map once per day
make_stars()
else
time = time
endif
dc update time
sun_xyz()
UpDateWater()
rem Show Textures rendered form camera 1 and 2
if shiftkey()=1 then paste image 500,0,0
if controlkey()=1 then paste image 501,0,0
rem update screen
sync
rem debug text
text 0,0,"FPS: "+STR$(screen fps())
text 0,12,"Time: "+STR$(time)
text 0,24,"Cam Pos X: "+STR$(camera position x(0))
text 0,36,"Cam Pos Y: "+STR$(camera position y(0))
text 0,48,"Cam Pos Z: "+STR$(camera position z(0))
text 0,60,"Cam Ang X: "+STR$(camera angle x(0))
text 0,72,"Cam Ang Y: "+STR$(camera angle y(0))
text 0,84,"Cam Ang Z: "+STR$(camera angle z(0))
rem end loop
loop
function sun_xyz()
sun_red =RGBR(dc get light color())
sun_green =RGBG(dc get light color())
sun_blue =RGBB(dc get light color())
sun_angle# = time*15.0
if time > 12.0
sun_ang_x# = sun_angle#-90.0
sun_ang_y# = (sun_angle#-360.0)+7.5
sun_ang_z# = 0.0
else
sun_ang_x# = sun_angle#-90.0
sun_ang_y# = (360.0-sun_angle#)+7.5
sun_ang_z# = 15.0
endif
//if time > 18.0
// moon_ang_x# = sun_ang_x#-180
// moon_ang_y# = sun_ang_y#-180
// moon_ang_z# = sun_ang_z#
//endif
moon_ang_x# = sun_ang_x#-180
moon_ang_y# = sun_ang_y#-180
moon_ang_z# = sun_ang_z#
//COLOR AMBIENT LIGHT RGB(sun_red,sun_green,sun_blue)
ROTATE LIGHT 0,INT(sun_ang_x#),INT(sun_ang_y#),INT(sun_ang_z#)
rem show no stars just before the sun rises
if time > 5.2 and time < 18.3
rem show no stars during the day
SET EFFECT CONSTANT FLOAT 1,"SkyOverlay",1.0
endif
rem show the stars after the sun sets
if time > 18.4 and time < 23.9
rem Moon or moons will be brighter than the stars
SET EFFECT CONSTANT FLOAT 1,"SkyOverlay",0.8
endif
rem Stars will be brighter than the moon or moons if you have more than one
if time > 0.0 and time < 5.2
SET EFFECT CONSTANT FLOAT 1,"SkyOverlay",0.5
endif
endfunction
function make_stars()
if bitmap exist(32)=1 then delete bitmap 32
if memblock exist(1)=1 then delete memblock 1
if image exist(galaxy_image)=1 then delete image galaxy_image
CLS RGB(0,0,0)
INK RGB(255,255,255),RGB(0,0,0)
create bitmap 32,star_res_x,star_res_y
set current bitmap 32
rem star pass for comets
FOR i=1 TO comets
x=RND(star_res_x) : y=RND(star_res_y)
INK RGB(255,255,255)
line x,y,x+3,y+3
NEXT i
rem star pass for large stars
FOR i=1 TO stars_large
x=RND(star_res_x) : y=RND(star_res_y)
INK RGB(255,255,255)
circle x,y,1
NEXT i
rem star pass for small stars
FOR i=1 TO stars_small
x=RND(star_res_x) : y=RND(star_res_y)
INK RGB(255,255,255)
DOT x,y
NEXT i
make memblock from bitmap 1,32
make image from memblock galaxy_image,1
if time = 0.0
texture object SKY_ID,0,galaxy_image
endif
set current bitmap 0
delete bitmap 32
sync
endfunction
//--------------
` Create Water
//--------------
function MakeWater(Obj,Shader,Img,ImgSize,Height#,cam_range#)
`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,cam_range#
set camera aspect c,Sw#/Sh#
backdrop on c
color backdrop c,rgb(0,0,0)
set camera to image c,Img+(c-1),ImgSize,ImgSize
set camera fov c,FOV
next c
`Make Water plain
load image "water\Waves.dds",Img+2
load image "water\Fresnel.bmp",Img+3
load image "water\WaterMask.bmp",Img+4
make object plain WaterObj,5000,5000
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 "water\Water.fx",Fx,0
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,0,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,0,0,WaterHeight#-30,0,0,-1,0
fog off
endif
set camera clip 2,1,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
Almost forgot this requires the latest dark clouds plugin