### Author Topic: Texture Blending on a heightmap/surfacemap  (Read 2601 times)

#### Marchioly

• byte
• Posts: 8
##### Texture Blending on a heightmap/surfacemap
« on: March 04, 2016, 05:34:33 pm »
I am loading a heightmap, and texturing it based upon the data stored in the map format. I would like to apply texture blending to this.

I use the following for preparing the triangles/UV coordinates

Code: [Select]
/**
* The terrain heights are calculated now. Now we have to build an
* Object3D from them.
*/
Object3D ground = new Object3D(width * height * 2);

for (int x = 0; x < width - 1; x++) {
for (int z = 0; z < height - 1; z++) {

int x1 = x * 10;
int x2 = (x + 1) * 10;

int z1 = z * 10;
int z2 = (z + 1) * 10;

float southwestY = heights[x][z];
float southeastY = heights[x + 1][z];

float northwestY = heights[x][z + 1];
float northeastY = heights[x + 1][z + 1];

/*
* Triangles start being drawn at the smallest 'x' Cartesian coordinate in jpct.
* You then go clockwise to fill in the rest of the points.
*
*0,1-1,1
* |  /|
* | / |
* |/  |
*0,0-1,0
*
* Above is a cheat sheet for the coordinates.
*
*
* TODO: Implement it such  we can select the triangle hypotenuse  for the tile based
* on surrounding textures. This should improve blending when that finally gets implemented.
*/

// 0,1
// |\
// | \
// |  \
// |___\
// 0,0, 1,0
new SimpleVector(x1, southwestY, z1), 0,0,
new SimpleVector(x2, southeastY, z1),0,1,
new SimpleVector(x1, northwestY, z2), 1,0,
fetchTexture(surfaces[x][z]));

//
//0,1____1,1
//   \  |
//    \ |
//     \|
//     1,0,
new SimpleVector(x1, northwestY, z2), 1, 0,
new SimpleVector(x2, southeastY, z1), 0, 1,
new SimpleVector(x2, northeastY, z2),1, 1,
fetchTexture(surfaces[x][z]));

// TODO
// ____

//     /|
//    / |
//   /  |
// /__ |
}
}

Does anyone have any tips or advice they could give me for making this look nicer?

#### EgonOlsen

• Posts: 12275
##### Re: Texture Blending on a heightmap/surfacemap
« Reply #1 on: March 04, 2016, 05:49:14 pm »
You could use texture splatting for that, but it requires that you actually build a custom splatting texture based on your terrain data and you have to use shaders for this. Here's a basic example: http://www.jpct.net/wiki/index.php?title=Texture_splatting_on_a_terrain

#### Marchioly

• byte
• Posts: 8
##### Re: Texture Blending on a heightmap/surfacemap
« Reply #2 on: March 04, 2016, 05:56:19 pm »
You could use texture splatting for that, but it requires that you actually build a custom splatting texture based on your terrain data and you have to use shaders for this. Here's a basic example: http://www.jpct.net/wiki/index.php?title=Texture_splatting_on_a_terrain

Ill give that a try. I was kind of relunctant because i have ~13 textures per tileset/ environment.

#### EgonOlsen

• Posts: 12275
##### Re: Texture Blending on a heightmap/surfacemap
« Reply #3 on: March 04, 2016, 06:01:04 pm »
That's not a problem unless you use more than 3 (plus one splatting texture) on each tile. Or you could try to combine the textures into fewer but larger ones.

#### Marchioly

• byte
• Posts: 8
##### Re: Texture Blending on a heightmap/surfacemap
« Reply #4 on: March 04, 2016, 08:33:05 pm »
That's not a problem unless you use more than 3 (plus one splatting texture) on each tile. Or you could try to combine the textures into fewer but larger ones.

Alright. Each tile/ square can only have 1 texture type (ex ground/floor/water) currently, but there are multiple textures per texture type. This give me the ability to have more varied terrain.

Ill think about posting the src when I am done. I have not really seen anything similar released for jpct yet.