@gg I cant get it to work with my terrain object properly. Since you wrote the shader I was wondering if you would be able to give it a shot. Here is my code.
Rem ***** Main Source File *****
time1# = timer()
set display mode 800,600,32
sync on: sync rate 0: sync
autocam off
backdrop on
Set Global Collision Off
set camera range 1,15000
` set camera fov 70
set normalization on
color backdrop rgb(64,64,255)
global hitDistance#
global hitObject
global ground_y#
`load effect "terrainFXv2.fx",1,0
load effect "GG Blended Bump Mapping Shader.fx", 1, 0
load image "grass1.bmp", 301
load image "rock4.png", 302
load image "sand1.bmp", 303
load image "gravel1.bmp", 304
load image "grass1 nmp.bmp", 305
load image "rock4 nmp.png", 306
load image "sand1 nmp.bmp", 307
load image "gravel1 nmp.bmp", 308
rem set the scale of the world
scale_land = 1000
land_scale = 10
grid_size = 10 `this dont change
rem pre-scale the objects
load object "terrain_mesh3.dbo",5000
`save object "terrain_mesh1.dbo",5000
scale object 5000, scale_land,scale_land/2,scale_land
last_tile = grid_size * grid_size
for new_tile = 1 to last_tile
clone object new_tile, 5000
position object new_tile,xx,0,zz
xx = xx + scale_land
if xx => scale_land *10
xx = 0
zz = zz + scale_land
endif
next new_tile
rem load and then flip the bitmap for proper orientation, for some reason dbp flips them on load.
`set current bitmap 1
image_size = 1000
load bitmap "map.png",333
flip bitmap 333
make memblock from bitmap 33,333
memblock1 = 33
size = get memblock size(memblock1)
for land = 1 to last_tile
LOCK VERTEXDATA FOR limb land,1,2
for a=0 to get vertexdata vertex count()-1
X#=GET VERTEXDATA POSITION X(a)+object position x(land)/land_scale
Z#=GET VERTEXDATA POSITION Z(a)+object position z(land)/land_scale
cx = x#`/amount#
cy = z#`/amount#
` works out where in memory to plot position
mem_y = int(cy)*(image_size*4)
mem_x = (int(cx)*4)
mem_location = mem_x + mem_y
rem this reads the heightmap and gets the appropiate number
if mem_location < get memblock size(memblock1)
height# = memblock byte(memblock1, mem_location)
else
height# = 0
endif
SET VERTEXDATA POSITION a,GET VERTEXDATA POSITION X(a),height#,GET VERTEXDATA POSITION z(a)
next a
unlock vertexdata
next land
v = make vector4(1)
for chunk = 1 to 100
texture object chunk, 0, 301 ` first detail map
texture object chunk, 1, 302 ` second detail map
texture object chunk, 2, 303 ` third detail map
texture object chunk, 3, 304 ` fourth detail map
texture object chunk, 4, 305 ` first normal map
texture object chunk, 5, 306 ` second normal map
texture object chunk, 6, 307 ` third normal map
texture object chunk, 7, 308 ` fourth normal map
` load effect "GG Blended Bump Mapping Shader.fx", 1, 0
set object effect chunk, 1
set effect constant float 1, "contrast",4.0
set effect constant float 1, "vertScale", 0.15
set vector4 1, 8, 8, 0, 0
set effect constant vector 1, "UVTiling", 1
next chunk
`imgCloud = 555
objCloud = 556
load image "cloud_a.png", 565,1
rem setup the atmospheric clouds
Make Object Plain 556, 150000, 150000
xRotate Object 556, 270
Position Object 556, 0, 2000, 0
Texture Object 556, 565
Scale Object Texture 556, 10, 10
set object transparency 556,4 `Set transparency on, and set the correct mode.
set current bitmap 0
rem make some water
make object plain 275, 10000,10000
xrotate object 275,90
position object 275, 5000,100,5000
ghost object on 275,2
texture object 275,565
camy# = 160
`make a player and hide it
make object cube 9999,2
position object 9999,5690,50,5960
hide object 9999
rem create out invisible raycast object
global rayObj = 9998
make object cube rayObj, 20
exclude object on rayObj
player = 9999
rem set this for raycasting in front of the player
second_ray_object = Player
for land = 1 to last_tile
`remsetup for sparkys collision
setupComplexObject land,0,2
next land
delete bitmap 333
`delete bitmap 888
delete memblock 33
delete object 5000
`FLUSH VIDEO MEMORY
time2# = timer()-time1#
do
set cursor 1,1
print "screen fps: ", screen fps()
print "camera x: ", startx#
print "camera y: ", starty#
print "camera z: ", startz#
print "ray distance: ",hitDistance#
print "terrain chunk intersected: ",hitObject
print "load time: ",time2#
`player controls
if leftkey()=1 then yrotate object 9999,wrapvalue(object angle y(9999)-1)
if rightkey()=1 then yrotate object 9999,wrapvalue(object angle y(9999)+1)
if upkey()=1 then move object 9999,3
if downkey()=1 then move object 9999,-3
`get player positions
px#=object position x(9999)
pz#=object position z(9999)
rem raycast for the player 1500 units out
startx# = camera position x()
starty# = camera position y()
startz# = camera position z()
rayCast(startx#,starty#,startz#,second_ray_object)
collide=intersectObject(0,1,px#,5000,startz#,px#,-5000,pz#,0)
if collide = 0
ground_y# = 0
else
ground_y# =GetStaticCollisionY ()
endif
`put player at the new height
position object 9999,px#,ground_y#+15,pz#
`simple camera follow
set camera to follow px#,ground_y#,pz#,object angle y(9999),10,55,2,0
`gosub time_update
fastsync
loop
time_update:
blue# = blue# + bInc#
if blue# =>255 Then bInc# = -0.1
if blue# =<0 Then bInc# = 0.1
if blue# >100
Color BackDrop Rgb(0,0,100)
Color Ambient Light Rgb(100,100,100)
else
Color BackDrop Rgb(0,0,blue#)
Color Ambient Light Rgb(blue#,blue#,blue#)
endif
fog distance blue# *100
Fog Color Rgb(blue#/2,blue#/2,blue#/2)
color backdrop Rgb(blue#/2,blue#/2,blue#)
`color backdrop 1,Rgb(blue#/2,blue#/2,blue#)
`set alpha mapping on 302,255-int(blue#/2)
`if blue# > 100 then hide object 302 else show object 302
return
function rayCast(startx#,starty#,startz#,second_ray_object)
position object rayObj,startx#,starty#,startz#
Set Object To object Orientation rayObj,second_ray_object
startx# = object position x(rayObj)
starty# = object position y(rayObj)
startz# = object position z(rayObj)
move object rayObj,5000
endx# = object position x(rayObj)
endy# = object position y(rayObj)
endz# = object position z(rayObj)
collide=intersectObject(0,1,startx#,starty#,startz#,endx#,endy#,endz#,0)
if collide = 0
hitDistance# = 0
hitObject = 0
else
hitDistance# = GetCollisionDistance ()
hitObject = collide
endif
endfunction