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.
(https://i.gyazo.com/a760c0a3f1433e8889bcdcdeaf561f5b.png)
I use the following for preparing the triangles/UV coordinates
/**
* 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
ground.addTriangle(
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,
ground.addTriangle(
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?
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 (http://www.jpct.net/wiki/index.php?title=Texture_splatting_on_a_terrain)
Quote from: EgonOlsen 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 (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.
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.
Quote from: EgonOlsen 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.
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.