Hello all,
I'm attempting to use the water shader from the Ultimate Shader Pack and I'm failing miserably. What I'm trying to do is get it to work from a function so it can be called whenever. You can obtain the Shader Pack by clicking this link:
http://files.odyssey-creators.com/files/Ultimate_DarkSHADER_Pack.zip
Here is the Demo code for the water shader:
`+++++++++++++++++++++++++
`Why We need clipping planes !
`+++++++++++++++++++++++++
`Set Up Screen
set display mode 1024,768,32
sync on
sync rate 0
hide mouse
`Set Camera 0
position camera 1100,50,800
set camera range 1,15000
autocam off
color backdrop rgb(155,155,155)
set camera fov 70
Fog On : Fog Color Rgb( 128, 128, 128 ) : Fog Distance 8192
`Set Camera 1 (Reflection)
make camera 1
set camera range 1,2,15000
set camera fov 1,70
set camera aspect 1,1.33
color backdrop 1,0
set camera to image 1,5,512,512
`Make Terrain
load image "data/texture.JPG", 1
load image "data/detail.jpg", 2
make object terrain 1
set terrain heightmap 1,"data/map.JPG"
set terrain scale 1,6,1.2,6
set terrain split 1,16
set terrain tiling 1,4
set terrain light 1,1,-0.25,0,1,1,0.75,0.5
set terrain texture 1,1,2
build terrain 1
position object 1,0,-38,0 `position so its below water line
`Make Skybox
load object "data/skybox2.x",3
set object light 3,0
set object texture 3,3,1
position object 3,1000,1000,1000
scale object 3,20000,20000,20000
yrotate object 3,180
`Make Water plain Object
load image "data/waves.jpg",6
make object plain 2,2500,2500
xrotate object 2,270
texture object 2,0,5
texture object 2,1,6
load effect "effects/water.fx",1,0
set object effect 2,1
Set Alpha Mapping On 2, 100 ` Force object to have minor transparency [ Change by Freddix ]
` Ghost Object On 2, 2
OldYpos# = Camera Position Y()
`Start loop
do
`Control Camera
cr#=0
cf#=0
if rightkey()=1 or KEYSTATE(32)=1 then cr#=-2
if leftkey()=1 or KEYSTATE(30)=1 then cr#=2
if upkey()=1 or KEYSTATE(17)=1 then cf#=2
if downkey()=1 or KEYSTATE(31)=1 then cf#=-2
ncr#=curvevalue(cr#,ncr#,5)
ncf#=curvevalue(cf#,ncf#,5)
cx#=cx#+mousemovey()*0.2
cy#=cy#+mousemovex()*0.2
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
YPos# = Camera Position Y()
`Position came 1 under the water!
If YPos# > 0
position camera 1,camera position x(),-Ypos#,camera position z()
rotate camera 1,-camera angle x(),camera angle y(),camera angle z()
Else
position camera 1,camera position x(),-Ypos#,camera position z()
rotate camera 1, -Camera angle x(),camera angle y(),camera angle z()
Endif
`Move water
ro#=wrapvalue(ro#+0.05)
position object 2,500+sin(ro#)*100.0,0,500+cos(ro#)*100.0
`Hide water
hide object 2
`Sync for reflecton cam
sync mask 0x00000002
`Minor changes by freddix to add in water fog effect ...
Ypos# = Camera Position Y()
If YPos# > 0 And OldYPos# < 0
Fog On : Fog Color Rgb( 128, 128, 128 ) : Fog Distance 8192
Else
If YPos# < 0 And OldYPos# > 0
Fog On : Fog Color Rgb( 24, 32, 48 ) : Fog Distance 5, 256
Endif
Endif
OldYPos# = YPos#
sync
`Show water
show object 2
`Paste camera reflection image
if controlkey()=1 then paste image 5,0,0
Set Cursor 0, 0 : Print Screen FPS()
`Sync for Main cam
sync mask 0x00000001
sync
loop
and here is my function for it:
function watersetup(waterobjnum,alpha)
make camera 1
set camera range 1,2,15000
set camera fov 1,70
set camera aspect 1,1.33
color backdrop 1,0
set camera to image 1,5,512,512
`Make Water plain Object
load image "media/textures/water/waves.jpg",6
make object plain waterobjnum,2500,2500
xrotate object waterobjnum,270
texture object waterobjnum,0,5
texture object waterobjnum,1,6
load effect "media/effects/water.fx",1,0
set object effect waterobjnum,1
Set Alpha Mapping On waterobjnum,alpha ` Force object to have minor transparency [ Change by Freddix ]
endfunction
function waterloop(waterobjnum)
`Position came 1 under the water!
position camera 1,camera position x(),-Ypos#,camera position z()
rotate camera 1,-camera angle x(),camera angle y(),camera angle z()
`Move water
ro#=wrapvalue(ro#+0.05)
position object waterobjnum,500+sin(ro#)*100.0,0,500+cos(ro#)*100.0
`Hide water
hide object waterobjnum
`Sync for reflecton cam
sync mask 0x00000002
`Show water
show object waterobjnum
`Sync for Main cam
sync mask 0x00000001
endfunction
Anyone see the problem? I'm completely lost, so if you have any comments or anything at all that may help, please post.
-Jim
Insert Signature Here