Texturing my terrain

Blitz3D Forums/Blitz3D Programming/Texturing my terrain

PaulJG(Posted 2003) [#1]
Would some kind soul be able to spare me a few minutes and take a look through my code. here

I got a really strange problem with it..

What it should be doing is, making a mesh.. then tiling it with the first top quarter of the texture. But for some reason its leaving these gaps between each quad on the mesh !?. I thought at first is was the texture coords - but its not.

Then maybe the mesh coords where screwy.. but they cant be, stretch the texture over the whole of the quads, its fine - stretch a certain section over a quad and you get this strange effect.



I've no idea why it is doing this !???.

(The whole area should be green, but its tinted purple - and it shows up gaps which shouldnt exist)


jfk EO-11110(Posted 2003) [#2]
Did you try to use the Texture Flag 48 ? (32 or 16: Clamp UV)


PaulJG(Posted 2003) [#3]
Didnt make any difference. :(


Floyd(Posted 2003) [#4]
I think you can make this precise by considering each texture pixel as a small square.
The texture is 256x256, so each pixel has width and height 1/256.

You want to map vertices to the *centers* of these squares.
Let delta# = 1.0 / 512.0 and then adjust by + or - this amount.

So (0, .5) would become (0+delta, .5-delta) etc.


Shambler(Posted 2003) [#5]
The problems with your way of texturing the terrain come from our old friends 'Bilinear Filtering' and 'MipMapping'.

I can understand what you are doing, you want several different tile textures but only want to use a single surface for your terrain.

Clamping the texture won't work as this clamps to 0.0 and 1.0 texture coordinates whereas you aren't using the whole of the 0.0 to 1.0 range.

There are 2 things you can do to reduce this effect.

The first is to bring your texture coordinates inwards, away from the edges of your texture.

AddVertex tt\surf,x+cenx#,y+ceny#,0,0.1,0.1,0                         
AddVertex tt\surf,x+cenx#,(y+1.0)+ceny#,0,0.1,0.4,0 
AddVertex tt\surf,(x+1.0)+cenx#,(y+1.0)+ceny#,0,0.4,0.4,0
AddVertex tt\surf,(x+1.0)+cenx#,y+ceny#,0,0.4,0.1,0


This will reduce the artifacts which come from running out of pixels to filter at the edges of your texture.

This will improve things but you will still get errors the further away from the camera the terrain is.

The only solution to that I believe is to turn off mipmapping but that isn't very desireable imo.

Other than that just use multiple surfaces to get the required result...depends on how many different surfaces you want to have I suppose.


PaulJG(Posted 2003) [#6]
Floyd, sorry mate - tried it - no difference.

Shambler, you hit the nail on the head - so I wasnt to blame (for once!). Doing as you suggested I've taken off mipmapping and decreased the coord values.

Seems to do the trick, no leaking or gaps. But what are the disadvantages to turning off mipmapping ? and how is it gonna effect my program ??.

And yeap - you got it, the final outcome of this little proggie will be to use multiple textures on one surface with only one one loaded texturemap !?. (and another over the top for shadows and lightmapping)

Thanks guys.


Shambler(Posted 2003) [#7]
Mipmapping is there to improve the quality of rendering.

It makes lower resolution copies of whichever texture you give it and uses them to render objects as they move into the distance.

This gets rid of 'sparklies' for want of a better word ^^ but does also introduce its own less noticeable defect which can be seen when it switches from one mipmap to the next ( you can see a line where they meet ).

Change your simple texture to one with some detail and try rendering it with mipmapping and without to see which method you prefer.