Posted: 4th May 2011 00:27
Hi, I am trying to use evolved's water shader but when I run the program all I am seeing is a grey screen. When right clicking, which should allow the camera to orbit the object, I can look up to the sky but not see the player. The problem seems to be with the update refraction and update reflection functions.
Also I'm using darkclouds. I don't know if there is a conflict between this and the water shader as I tried adding darkclouds to the evolved's demo and the compiler fell over.
I'm pretty new so my code isn't the best.
Thank you for your help, any comment is appreciated.[Rem ***** Main Source File *****
Rem Project: Robot in a Beautiful World
Rem Created: Saturday, April 23, 2011
remstart Notes
Android-Idle has 27 frames of animation
remend
rem GAME SETUP
sync on
sync rate 60
hide mouse
Sw=1280:Sh=1024
set display mode Sw,Sh,32,1
autocam off
backdrop off
set camera range 0,1,100000
rem LOAD IMAGES
load image "Textures\Grass1.jpg",3 `base texture for world
load image "Textures\Grass3.jpg",4 `detail texture for world
rem CREATE WORLD
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "Textures\Heightmaps\bworld1.bmp" ` set the heightmap
set terrain scale 1, 3, 0.6, 3 ` set the scale
set terrain split 1, 16 ` split value by 16 * 16
set terrain tiling 1, 4 ` detail map tiling
set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture 1, 3, 4 ` base and detail texture
build terrain 1 ` finally build the terrain
rem create sky
`load image "Models\World\Skies\bright sky texture.jpg", 2
`make object sphere 3,-1000
`position object 3,0,200,0
`texture object 3,2
rem CREATE SKY WITH DARKCLOUDS
rem half-fill the sky with clouds
dc set cloudy 0.5
rem set sky brightness to 1
dc set brightness 1
rem set wind to 30 mph at 270 degrees (heading west)
dc set wind 5,270
rem init with texture number 1, and number of keyframes per day
dc init 1,4
rem starting at 9am
time#=7.0
rem the update command creates the cloud texture
dc update time#
rem show texture 1 as the backdrop
texture backdrop 1
rem CREATE PLAYER
load object "Models\Android\H-Android-Idle.x", 2
append object "Models\Android\H-Android-Move.x",2, total object frames (2) + 1
load image "Models\Android\robot.dds", 5
texture object 2,5
yrotate object 2,180
position object 2,1000,0.1,1000
`Make Water(Objnum , Fxnum ,Imgnum ,Imgsize, Water Height)
MakeWater(500,500,500,512,95)
position object 500,1500,41,100
rem WALK FLAG
walk = 0
rem VARIABLES
rem player variables
PlayerSpeed# = 0.2
rem MAIN LOOP
do
TEXT 0,0,"fps "+str$(screen fps())
TEXT 0,10,"time "+str$(time#)
Text 0,20, "Object X "+str$(plx#)
Text 0,30, "Object Y "+str$(ply#)
Text 0,40, "Object Z "+str$(plz#)
rem SUB-ROUTINES
gosub _player_control
gosub _camera_control
if mouseclick() = 1
gosub _Robo_Scope
ENDIF
`Update Water
UpDateWater()
rem animation ammend
if walk = 1
loop object 2,28,total object frames(2)
else
loop object 2,0,27
ENDIF
rem darkclouds sky
rem step through the day
time#=time#+100.0/(60.0*60.0*60.0)
rem update clouds
dc update time#
sync
LOOP
rem sub-routines
rem player control
_player_control:
a# = get terrain ground height(1,object position x(2),object position z(2))
position object 2, object position x(2),a#+1,object position z(2)
if keystate(17) = 1
move object 2,-PlayerSpeed#
walk = 1
else
walk = 0
endif
if keystate(31) = 1
move object 2,PlayerSpeed#
walk = 1
endif
if keystate(30) = 1
yrotate object 2,object angle y(2)-1.0
walk = 1
endif
if keystate(32) = 1
yrotate object 2,object angle y(2)+1.0
walk = 1
endif
if shiftkey() = 1
PlayerSpeed# = 2
else
PlayerSpeed# = 0.2
ENDIF
Return
rem camera control
_camera_control:
plx# = object position x(2)
ply# = object position y(2)
plz# = object position z(2)
set camera to follow plx#,ply#,plz#,object angle y(2)-180,5,4,10,1
if mouseclick() = 2
camyangle#=Wrapvalue(camyangle#+Mousemovex())
camxangle#=camxangle#+MousemoveY()
`Apply limits on the camera x angle (i.e. y position) - this way camera is prevented from going up too high or too low
If camxangle#>90 then camxangle#=90
If camxangle#<0 then camxangle#=0
`Here i'm setting the distance so that the camera will be right on top of the character when camera is pointing straight down
`Basically, when the camera is on the ground point straight at the character, the distance should be 200. When it straight above, distance should be 0. Therefore I use this formula to achieve just that
dist#=15-(camxangle#*50/90)
rem Update camera position
`Use newvalues to find a point 200 units *behind the character's position but using camera's yangle value so that user can control camera's rotation around the character object
camx#=NewXValue(Object position x(2),camyangle#,-1*dist#)
camy#=NewYValue(Object Position y(2),camxangle#,-200)
camz#=NewZValue(Object position z(2),camyangle#,-1*dist#)
`Curve the camera values
camx#=Curvevalue(camx#,Camera Position X(0),5.0)
camy#=Curvevalue(camy#,Camera Position Y(0),5.0)
camz#=Curvevalue(camz#,Camera Position Z(0),5.0)
`Update camera position
Position Camera 0,camx#,camy#,camz#
`Keep camera pointing at character at all times
Point Camera 0,Object position X(2),Object position Y(2),Object Position Z(2)
ENDIF
Return
_Robo_Scope:
position camera 0,OBJECT POSITION X(2),OBJECT POSITION Y(2)+2,OBJECT POSITION Z(2)
`360 camera movement
`rotate camera camera angle x()+(mousemovey()/4.0),camera angle y()+(mousemovex()/4.0),0
camRotY = wrapvalue(camera angle y(0)+ mousemovex()*0.3)
camRotX = wrapvalue(camera angle x(0)+ mousemovey()*0.3)
rotate camera camRotX,camRotY,0
Return
//--------------
` Create Water
//--------------
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 "Shaders/Water+Terrain/Media/Waves.dds",Img+2
load image "Shaders/Water+Terrain/Media/Fresnel.bmp",Img+3
load image "Shaders/Water+Terrain/Media/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 "Shaders/Water+Terrain/FX/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,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
]