Let's get the whole thing working - then make it faster.
This version includes a simple distortion object for an additional final render. If that's the sort of overall set-up you had in mind perhaps you could replace my distortion object with yours and see if it works as you require. Then we can try to speed it up.
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0
`hide mouse ` for GG's benefit :)
rem constants
#constant IMGForceField 3
#constant IMGForceFieldNormal 4
#constant RefractionFX 1
#constant NormalMappingFX 2
rem load effects
load effect "HeatHaze.fx" , RefractionFX , 0
load effect "NormalMapping.fx" , NormalMappingFX , 0
rem load images
load image "force_field.png" , IMGForceField
load image "force_field_normal.png" , IMGForceFieldNormal
rem make ground and texture with something inviting
make object plain 1 , 100 , 100
xrotate object 1 , 90
load image "sand.png" , 1
load image "sand_normal.png" , 2
texture object 1 , 0 , 1
texture object 1 , 1 , 2
scale object texture 1 , 8 , 8
set object effect 1 , NormalMappingFX
rem make distortion object
make object plain 1001 , 40 , 30 , 50, 50
position object 1001 , 0 , 0 , 25
xrotate object 1001, 270.0
lock object on 1001
set object ambient 1001 , 0
set object light 1001 , 0
set object filter 1001 , 0
`set object mask 1001, 1
` store vertices in an array
type vertex
x as float
y as float
z as float
endtype
dim verts(51*51-1) as vertex
lock vertexdata for limb 1001, 0
idx = -1
for x = 0 to 50
for y = 0 to 50
inc idx
verts(idx).x = get vertexdata position x(idx)
verts(idx).y = get vertexdata position y(idx)
verts(idx).z = get vertexdata position z(idx)
next y
next x
unlock vertexdata
rem create second camera and render to image 1001
make camera 1
color backdrop 1 , 0
set camera to image 1 , 1001 , screen width() , screen height()
rem create third camera to show distortion object
make camera 2
set camera to image 2, 1002, screen width() , screen height()
rem texture image 1001 to screen plain
rem texture object 1001 , 1001
rem texture image 1002 to screen plain
texture object 1001 , 1002
rem make a force field
load object "force_field.x" , 2
texture object 2 , 0 , 1001
texture object 2 , 1 , IMGForceField
texture object 2 , 2 , IMGForceFieldNormal
set object effect 2 , RefractionFX
scale object texture 2 , 0.3334 , 0.3334
set object transparency 2, 2
rem position cameras - both in the same place and facing the same way
position camera 0, 0 , 10 , -15
point camera 0, 0 , 0 , 0
position camera 1, 0 , 10 , -15
point camera 1, 0 , 0 , 0
position camera 2, 0 , 10 , -15
point camera 2, 0 , 0 , 0
rem main loop
frames# = 0.0
do
inc frames#
simpleDistort(frames#)
rem scroll forcefield texture
if stopped = 0 then scroll object texture 2 , 0 , 0.003
if inkey$() = "s" then stopped = 1
` first render the main scene WITHOUT the force field to image 1001
show object 1
hide object 2
hide object 1001
sync mask 2 ` render camera 1 to image 1001
sync
` render main scene WITH force field object included to image 1002
show object 2
sync mask 4 ` render camera 2 to image 1002
sync
` render final screen image - i.e. image 1002 displayed on distortion object
hide object 2
hide object 1
show object 1001
sync mask 1
sync
rem end of main loop
loop
rem end program
end
function simpleDistort(frames#)
fX# = sin(frames#)
fY# = cos(frames#)
lock vertexdata for limb 1001, 0
idx = -1
for y = 0 to 50
for x = 0 to 50
inc idx
if (x>0) and (x<50) and (y>0) and (Y<50)
offsetX# = cos(x-25.0)*0.8*fX#
offsetY# = cos(y-25.0)*0.8*fY#
set vertexdata position idx, verts(idx).x+offsetX#, 0.0, verts(idx).z+offsetY#
endif
next x
next y
unlock vertexdata
endfunction