How do I create a terrain with tiled textures?

Blitz3D Forums/Blitz3D Beginners Area/How do I create a terrain with tiled textures?

fraggle(Posted 2005) [#1]
Hi. I want to create an outdoor terrain with tiled graphics. The tiles have to be changed in-game to, for example, build streets. I have tried out some solutions, but non of them worked well. In OpenGL I would bind the corresponding texture per quad. From my understanding, i can only asign ONE texture per entity (I am not speaking about multi texturing) so i tried to generate a mesh with mapsizex*mapsizey surfaces(each surface contains two triangles to represent a quad) and painted them individualy with the texture. This is working but really slow:(
I do not like the idea to work with one big texture and painting in the texture itselfe ingame, because the terrain should be 8192^2 minimum and the texture would be really big to get a nrea good looking experience.

Any ideas?


jfk EO-11110(Posted 2005) [#2]
8192^2? you must be kidden. This is 128 million triangles. No way. Do you really need to display all of it onscreen? I doubt it. So how about to hold your terrain data in an array, bitwise to save space. Now all you have to do is creating a littel mesh with everything that is visible onscreen. I think you can do that every frame without to lose too much performence.


PowerPC603(Posted 2005) [#3]
You could have 1 big texture, which contains all other textures.
You can have a road-texture where the road goes left-right (horizontally), up-down (vertically), and diagonally.
This would be one texture of 256x256, with 4 parts in it (each part 128x128).

Then when you change one quad's texture, set the UV-coordinates to the correct sub-texture.

I've played with this before in 3DS Max.
I had one model with only one surface (one texture) and each quad's UV-coords where adjusted manually to get each quad show a different part of the texture.
I even imported the B3D model into Blitz3D and it worked fine.

This way, you can have 100s of quads use the same part of the big texture, where other quads use a different part.


fraggle(Posted 2005) [#4]
I told about the map size, not the amount of triangles. Using a LOD terrain algorythm like ROAM or roetger will lover the triangles down. Trying to make some sort of tiles of LOD terrains will give you problems at the borders of the terrain tiles like strange looking poppings. Nevertheless:
Creating a mesh from 3ds would work for static streets. Creating them ingame wouldn't. Well... wouldn't with my information. That is what i hoped for. someone, knowing, how to generate a mesh ingame with each vertex textured differently. and this at an acceptable performance:)

some first tries with really bad performance:

Function CreateTerrain(sizeX%, sizeY%)
mesh=CreateMesh()
tex=LoadTexture( "mossyground.bmp" )
brush1=CreateBrush()
BrushTexture brush1,tex

For x=0 To sizeX%-1
For z=0 To sizey%-1
surface=CreateSurface(mesh)
v0=AddVertex(surface,x+0,0,z+0,0,0)
v1=AddVertex(surface,x+0,0,z+1,0,1)
v2=AddVertex(surface,x+1,0,z+1,1,1)
t0=AddTriangle(surface,v0,v1,v2)
v0=AddVertex(surface,x+0,0,z+0,0,0)
v1=AddVertex(surface,x+1,0,z+1,1,1)
v2=AddVertex(surface,x+1,0,z+0,1,0)
t0=AddTriangle(surface,v0,v1,v2)
PaintSurface (surface, brush1);or some other brush.. depending on x,z
Next
Next
Return mesh
End Function


fraggle(Posted 2005) [#5]
To clarify: I made a snapshot of the battlefield editor:

this is what i want to be able to do:)


Nik Green(Posted 2005) [#6]
Hi fraggle

Surfaces seem to hit performance more than tris do. Try creating only one surface for each texture (or brush) and add tris to the appropriate surface for each square.

Hope this helps.


fraggle(Posted 2005) [#7]
I have found a demo doing the work in "samples\birdie\Brush Tiles". Do not yet understand the use there of FindSurface(mesh, brush) in the function "Function Create_Map(tilex,tilez,tile)" but it definetly boosts the performance a lot. Only limitation is, that the terrain grid can't be bigger than 127*128. This seems to be some Blitz3d max poligon limitation. Ok. Since i do have to use a quad-tree algo to lower the objects, shown in the map, I will now do the subdivision with the map to a 64*64 level. Thank you for your help.


Xaron(Posted 2005) [#8]
Hi fraggle,

take a look at this:

http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=makakoman04012003155225&comments=no

Regards - Xaron


octothorpe(Posted 2005) [#9]
Do not yet understand the use there of FindSurface(mesh, brush) in the function "Function Create_Map(tilex,tilez,tile)"

"samples\birdie\Brush Tiles" creates a mesh with one surface per tile graphic, which is better than one surface per tile, but it does so in a convoluted way using FindSurface() and redundant brushes:

First it creates a brush for each grid square - I'm not sure how brushes are stored internally, but the program actually calls CreateBrush() 1024 times. Next, it cycles through the grid squares again, to create triangles. It attempts to find an existing surface which has already been painted with the same brush properties; if it cannot find one it creates a new surface and paints it. Herein lies the trickery: FindSurface() finds a surface painted with the same brush *properties* as the brush you pass it - even though you may have 900 brushes, one for each tile of grass, any one of these will return the surface you created for the first tile which used a similar [congruent?] brush. The resulting mesh will consist of 8 surfaces, one for each brush (i.e. terrain type).

P.S. Your Battlefield Editor looks nice, keep up the good work! :D


Raitsun(Posted 2005) [#10]
P.S. Your Battlefield Editor looks nice, keep up the good work! :D


It's not his Editor. It's the Editor of the Game "Battlefield" ;-]


sswift(Posted 2005) [#11]
Fraggle:
Did you try my terrain system?

If that didn't work out for you, then you're in trouble. :-)

If you need more terrain tiles an/or greater speed then you'd probably need to make a terrain system which combines multiple objects that use the same texture into a single object.

You might want to check out my foliage system. I no longer support it, but it is free:

www.seamlesstexturegenerator.com/foliagesystem-062.zip

The foliage system combines meshes like the trees you will see in the demo using octrees. It should work just as well with terrain squares you create and pass to it.

I don't provide support for the foliage system though so you're on your own if you try to do anything with it.

If you combined the foliage system with my terrain system you might be able to get a terrain up and running that is much faster at a larger size.

The foliage system handles multiple levels of detail which is what allows it to show high poly meshes up close, and lower detail ones in the distance. The lower detail ones are combined into single surfaces. The higher detail ones aren't and can't be or they'd exceeed the number of polys per surface allowed in Blitz.

The drawback to this method is that it uses a lot of video memory and ram for storing the meshes, and I'm not sure how much, or how far it can be pushed. You'd have to experiment. It may be that it would choke on the terrain sizes you need, or even those my terrain system can produce.

Another drawback is the foliage will be static unless you have that as a seperate element which you animate and position yourself.

The upside of this method is theoretically it is as fast as you can get in Blitz rendering highly detailed terrains. It packs the most polygons into the fewest surfaces for a particular scene, and does not calculate anything on the fly except which entities to show.


sswift(Posted 2005) [#12]
Just looked at your screenshot. To do that fat basically you need to combine as many of those "mud" tiles into a single surface in a single entitiy. Since they all use the same texture you can stick all the polygons in one surface.

But you might not be able to put all the mud tiles in the entire level in the single surface and besides that might be slow to render. So you'll need to decide on the size of area which each entity will cover, and then only add those mud tiles which fall into that area to each entity.

My foliage system does something like this when you add meshes to it. But again, I can't support it. You'll have to figure it out on your own or get someone else to assist you, I'm way too busy on a project right now to explain it. :-)


octothorpe(Posted 2005) [#13]
Consider putting all your tiles on one surface, using VertexTexCoords() to select separate tile graphics.


fraggle(Posted 2005) [#14]
Thank you for your responses.
Now I have to go to the research phase again *g*.
Xaron: I will have a near look at the algo. Unfortunatly I can't use endless terrains and the engine gets an out of memory exception really fast if i try to higher the size.
octothorpe: thank you. that clarifies a lot.
sswift:
Let me some days to understand you code:) I recognize some LOD code, but I am not really in love with basic. I think, you are talking about a quadtree and not an octree. I hoped, Blitz3d would be a scene graph and do the oculsion culling for me... I hope, I can ignore quadtrees with the terrain itself. For the game objects; this will be server work.
At the moment I try to get the engine working with terrain tiles. I divided the big terrain (4097*4097) by 64*64 pieces and show 4-16(depending on computer speed) of them. Depending on the camera/player position, I destroy and regenerate the tiles or meshes. To reduce the pause while generating a new tile, I have a delay between the creation of the new tiles, so in fact, one tile per 1-some frames are generated. (noticable, but not as disturbing as before:) ). I have written a dll to start a java virtual machine and execute any static function in any java class to get the network code running (no multithreading in blitz3d). I try to get the generation of the tiles and the creation/removing of objects to the java side, so I could implement the ROAM 2.0 algorithm from Trent Polack and move the vertex data over a memory bank. If someone sees a 4097*4097 or even 8193*8193 map with the ability to texture each quad individually, give me a shout please. I have bought blitz3d as an ideal prototyping tool... why can't I accept some limitations?;)


fraggle(Posted 2005) [#15]
and sorry... autor of ROAM is Mark Duchaineau. Trent Polack has worked out the new version with him. Just to ease some lawyers;)