Hi,
I want to texture a spherical terrain with the HeightBasedTerrain Material. So I customized it a little for my needs. I made an own material definition and changed two lines of the HeightBasedTerrain.frag :
line 19:
[java]
//float height = position.y;
float height = sqrt((position.x * position.x) + (position.y * position.y) + (position.z * position.z));[/java]
line 70
[java]return (blend.y * terrainColor + blend.x * terrainColor + blend.z * terrainColor);[/java]
The octahedron from which the sphere is build, already has distorted textures. The upper and lower triangles are okay. On the sides you see the distortion. Here is a picture:
<br />
<br />
<br /><br />
These are the initial buffer values. Here the vertex positions:
[java] //Intial vertex positions.
vertPositions[0][0] = new Vector3f(0, 0, 1);
vertPositions[0][1] = new Vector3f(1, 1, 0);
vertPositions[0][2] = new Vector3f(-1, 1, 0);
vertPositions[1][0] = new Vector3f(0, 0, 1);
vertPositions[1][1] = new Vector3f(1, 1, 0);
vertPositions[1][2] = new Vector3f(1, -1, 0);
vertPositions[2][0] = new Vector3f(0, 0, 1);
vertPositions[2][1] = new Vector3f(1, -1, 0);
vertPositions[2][2] = new Vector3f(-1, -1, 0);
vertPositions[3][0] = new Vector3f(0, 0, 1);
vertPositions[3][1] = new Vector3f(-1, -1, 0);
vertPositions[3][2] = new Vector3f(-1, 1, 0);
vertPositions[4][0] = new Vector3f(0, 0, -1);
vertPositions[4][1] = new Vector3f(1, 1, 0);
vertPositions[4][2] = new Vector3f(-1, 1, 0);
vertPositions[5][0] = new Vector3f(0, 0, -1);
vertPositions[5][1] = new Vector3f(1, 1, 0);
vertPositions[5][2] = new Vector3f(1, -1, 0);
vertPositions[6][0] = new Vector3f(0, 0, -1);
vertPositions[6][1] = new Vector3f(1, -1, 0);
vertPositions[6][2] = new Vector3f(-1, -1, 0);
vertPositions[7][0] = new Vector3f(0, 0, -1);
vertPositions[7][1] = new Vector3f(-1, -1, 0);
vertPositions[7][2] = new Vector3f(-1, 1, 0);[/java]
Here the intial values for the index buffer:
[java]
indexParts[0][0] = 0; indexParts[0][1] = 1; indexParts[0][2] = 2;
indexParts[1][0] = 1; indexParts[1][1] = 0; indexParts[1][2] = 2;
indexParts[2][0] = 2; indexParts[2][1] = 1; indexParts[2][2] = 0;
indexParts[3][0] = 1; indexParts[3][1] = 0; indexParts[3][2] = 2;
indexParts[4][0] = 1; indexParts[4][1] = 0; indexParts[4][2] = 2;
indexParts[5][0] = 0; indexParts[5][1] = 1; indexParts[5][2] = 2;
indexParts[6][0] = 0; indexParts[6][1] = 1; indexParts[6][2] = 2;
indexParts[7][0] = 0; indexParts[7][1] = 1; indexParts[7][2] = 2;[/java]
And this is how I compute the texture coordinates. I guess here must be the problem. I got the formula from the german wikipedia de.wikipedia.org/wiki/UV-Koordinaten. I also tried the formula from the english wikipedia en.wikipedia.org/wiki/UV_mapping. Same problem, might be just another notation? Not able to determine that
[java]new Vector2f(vertPositions[i][0].getX() / vertPositions[i][0].length(), vertPositions[i][0].getY() / vertPositions[i][0].length());[/java]
I hope the two dimensional arrays are not too confusing. I split up the octahedron in to 8 meshes. Has someone an idea what could be wrong with my way of computing the texture coordinates?
Greetings