In the forums often was said that it is impossible to create reflective and rippling water in DBC because the missing possibility to user shader.
This program is a proof of concept, that it is possible to do. the reflections and the movement of the water are all calculated in the program.
And as a nice side effect the program will run on a older graphic card without shader support (with DX8).
Credits: The rippling is based on Coldfire's code
setbestscreen()
backdrop on
color backdrop rgb(128,128,255)
hide mouse
sync on
randomize timer()
` variables to move the water
dim grid1#(50,50)
dim grid2#(50,50)
dim tempgrid#(50,50)
dim velocity#(50,50)
dim smoothed#(50,50)
` the backdrop
make object plain 1,4096,1024
load image "plants.bmp",10
texture object 1,10
set object 1,1,0,1
position object 1,1400,300,1400
yrotate object 1, 45
` the water
make matrix 1,1024,1024,50,50
make matrix 2,1024,1024,50,50
` the Beach
make matrix 3,2048,2048,20,20
randomize matrix 3,80
for x=7 to 13
for y=6 to 13
set matrix height 3,x,y,-10
next y
next x
for x=1 to 6
for y=0 to 14
set matrix height 3,x,y,0
next y
next x
for x=1 to 15
for y=0 to 6
set matrix height 3,x,y,0
next y
next x
load image "boden.bmp",3
prepare matrix texture 3,3,1,1
set matrix wireframe off 3
update matrix 3
` texture the water
`
` the water is created from 2 matrices
`
` the upper contains a water texture but is ghosted
` the lower (m2) will later contain a picture to simualte the reflections
load bitmap "water03.bmp",1
flip bitmap 1
mirror bitmap 1
set current bitmap 1
get image 1,0,0,bitmap width(1), bitmap height(1),1
set current bitmap 0
` textures are applied to the matrices
set matrix wireframe off 1
set matrix wireframe off 2
prepare matrix texture 1,1,50,50
prepare matrix texture 2,1,50,50
no=1
for x=0 to 49
for y=49 to 0 step -1
set matrix tile 1,x,y,no
set matrix tile 2,x,y,no
no=no+1
next y
next x
ghost matrix on 1
update matrix 1
position matrix 2,0,-1,0
update matrix 2
position matrix 3,-512,-7,-512
` we create a picture (refelctions.bmp' to texture
` matrix 2 with the reflections
position camera -128,230,-128
point camera 512,0,512
sync
if file exist("reflections.bmp") then delete file "reflections.bmp"
save bitmap "reflections.bmp"
load bitmap "reflections.bmp",20
set current bitmap 20
get image 20,0,0,bitmap width(20), bitmap height(20)/2
set current bitmap 0
prepare matrix texture 2,20,50,50
no=1
for x=0 to 49
for y=49 to 0 step -1
set matrix tile 2,x,y,no
no=no+1
next y
next x
update matrix 2
position camera 0,230,0
point camera 4096,0,4096
do
for x = 1 To 48
for y = 1 To 48
velocity#(x,y) = -1*grid2#(X, Y)
smoothed#(x,y) = (grid1#(X - 1, Y) + grid1#(X + 1, Y) + grid1#(X, Y - 1) + grid1#(X, Y + 1) + grid1#(X + 1, Y - 1) + grid1#(X - 1, Y + 1) + grid1#(X - 1, Y - 1) + grid1#(X + 1, Y + 1)) / 9
grid2#(X, Y) = smoothed#(x,y) * 2 + velocity#(x,y)
grid2#(X, Y) = grid2#(X, Y) * 0.94
set matrix height 1,x,y,grid1#(x,y)
set matrix height 2,x,y,grid1#(x,y)
next Y
next X
for x = 0 to 49
for y = 0 to 49
tempgrid#(x,y)=grid2#(x,y)
grid2#(x,y)=grid1#(x,y)
grid1#(x,y)=tempgrid#(x,y)
next y
next x
update matrix 1
update matrix 2
sync
if inkey$()="p"
save bitmap "screenprint.bmp"
end
endif
if rnd(15)=1 then grid1#(rnd(4)+8,rnd(4)+8)=-96
loop
end
function setbestscreen()
remstart
-----------------------------------------------------------------------------
The function will look for the highest available reolution on the system
and set it. Highest is defined as highest number of pixels, ignoring the
color-depth.
the function will work in DBclassic and DBpro
-----------------------------------------------------------------------------
remend
perform checklist for display modes
mwi=640:mhi=480:mde=16
for t=1 to checklist quantity()
wi=checklist value a(t) :` Width
hi=checklist value b(t) :` Height
de=checklist value c(t) :` Depth
if ((wi*hi)+de) > ((mwi*mhi)+de)
mwi=wi
mhi=hi
mde=de
endif
next t
set display mode mwi,mhi,mde
endfunction
I will attach the source, the media and a executable in a rar-file