multiple texturing

Blitz3D Forums/Blitz3D Beginners Area/multiple texturing

grindalf(Posted 2005) [#1]
i have a greyscale terrain and i want to texture the low flat sections with my grass texture and the higher steeper sections with a rock texture how do i place textures to specific locations on my terrain.


Sir Gak(Posted 2005) [#2]
Are you using a bump-map for the terrain?


grindalf(Posted 2006) [#3]
sorry i dont know what a bump map is but im useing a bmp then loadterrain


Matty(Posted 2006) [#4]
Edit:

here is an example of the method below:

http://home.swiftdsl.com.au/~gezeder/lloyd/texture.zip

(225 kb download)



A fairly simple way is the following:

Say you have a grass texture and a rocky mountain texture, then using your heightmap (the bitmap you use when you call load terrain) you create a new texture which is a colour map for the terrain. The color of each pixel on this texture is determined by, for example, reading the brightness of the pixel on the heightmap - if it is high then the ground is rocky there, if it is low then it is grassy and if it is somewhere in between then the resultant pixel on the colour map is a value somewhere between the 'grassy' and 'rocky' texture at that point. You then apply this texture to your terrain.

If you want to have tiled textures, ie a separate grass texture on some parts of a blitz terrain and a separate rocky texture on other parts of a blitz terrain I don't think you can do that, although it could be done on a 'mesh' terrain which is loaded with 'loadmesh'.

Some pseudo code for generating the texture I mentioned above would be like this:

rockytexture=loadtexture("some rocky texture") 
grassytexture=loadtexture("some grassy texture")
heightmap=loadtexture("your greyscale bitmap here which you use with load terrain...")
colourmaptexture=createtexture(texturewidth(heightmap),textureheight(heightmap))

Dim R(3),G(3),B(3)

for x=0 to texturewidth(heightmap)-1
for y=0 to textureheight(heightmap)-1

setbuffer texturebuffer(heightmap)
getcolor x,y ;use readpixel/readpixelfast instead for more speed this is just for making the example simple

R(0)=getred()
G(0)=getgreen()
B(0)=getblue()

setbuffer texturebuffer(rockytexture)
getcolor x,y
R(1)=getred()
G(1)=getgreen()
B(1)=getblue()
setbuffer texturebuffer(grassytexture)
getcolor x,y
R(2)=getred()
G(2)=getgreen()
B(2)=getblue()


H#=float(R(0)+G(0)+B(0))/(255.0+255.0+255.0) ;value between 0-1 for height of ground at this point....

IF H#>0.8 then R(3)=R(1):G(3)=G(1):B(3)=B(1) ;use rock texture for high areas...

IF H#<0.2 then R(3)=R(2):G(3)=G(2):B(3)=B(2);use grassy texture

IF H#<=0.8 and H#>=0.2 then 
R(3)=float(R(1))*(H#-0.2)/0.6 + float(R(2))*(0.8-H#)/0.6
If R(3)>255 then R(3)=255

G(3)=float(G(1))*(H#-0.2)/0.6 + float(G(2))*(0.8-H#)/0.6
If G(3)>255 then G(3)=255

B(3)=float(B(1))*(H#-0.2)/0.6 + float(B(2))*(0.8-H#)/0.6
If B(3)>255 then B(3)=255


endif 
setbuffer texturebuffer(colourmaptexture)
color R(3),G(3),B(3)
plot x,y
next
next
 setbuffer backbuffer()
terrain=loadterrain("your greyscale heightmap texture")
entitytexture terrain,coulourmaptexture
;you may need to scale the texture accordingly....


I just wrote this before going to bed so it may not be quite right.

EDIT - change all the 'getred, getgreen get blue to colorred, colorgreen colorblue - forgot the specific command name..


grindalf(Posted 2006) [#5]
thanks thats exactly what i wanted