Jon
10-06-2007 23:41:56
I'm close to the end of my rope on this one, and hopefully someone else can see something.
In short, I am seeing a problem with registration of textures on the terrain -- there is a slight shift which I cannot account for. Put another way, the texture coordinates passed to the shader don't line up with where I believe the terrain is.
Also, let me make clear that texturing is for the most part correct, so there is no major miscalculation. The land texture follows the shoreline of a test island, with only a few problem spots.
Perhaps an example will make this clearer. Here is a wireframe screenshot, I prefer a wireframe in this case so we can see the triangles.
OK, we can see terrain sloping up on the right side. If we pick a point on that triangle's face and get the texture coordinates, they are:
0.195789, 0.917363
Now, since I believe that these coordinates are page-based, we can translate these values into tile coordinates:
1.566313, 7.338906
Tile 1, 7 is displayed on the debug overlay. So far, so good. The page is (4,2), which can be verified in the debugger.
Lets see what is known about this page. I have a split heightmap, and I have a split texture index. Opening these in Photoshop I see they are in agreement, and the outline of the shore on these files can be visually matched to the rendered terrain. Well, mostly. There is the problem of this rising point on the right of the wireframe: it is not supposed to be there.
Given that pages are 513 pixels wide, the texture coordinates can be translated into texel coordinates (for the index): 99, 468. Using 512 pixels for the calculation does not change the texel for this point, so that isn't the problem.
Both the heightmap png and the index png show this point at sea level.
The terrain generator dumps the following information for this point, and the 8 surrounding points:
(It is likely not important, but texture 0 is dirt and texture 208 is water). The points are displayed in the following order:
That can also be seen from the coordinates listed in the output, but it is easier if we don't have to think too much about that. And again, the center point (5) corresponds to face on the rising triangle.
Each of the points have elevation 0. So, stitching with nearby vertexes should not be accounting for the problem.
The split height map shows that point as having elevation 0. The index says that point should be textured as water. And indeed, it is shown as a nice chunk of water rising up out of the ocean.
Going further, I have instrumented the vertex buffer loading for this tile.
Again, all of the surrounding points are seen as being at elevation 0.
And yet, the wireframe shows the point above 0. What am I missing here?
In short, I am seeing a problem with registration of textures on the terrain -- there is a slight shift which I cannot account for. Put another way, the texture coordinates passed to the shader don't line up with where I believe the terrain is.
Also, let me make clear that texturing is for the most part correct, so there is no major miscalculation. The land texture follows the shoreline of a test island, with only a few problem spots.
Perhaps an example will make this clearer. Here is a wireframe screenshot, I prefer a wireframe in this case so we can see the triangles.
OK, we can see terrain sloping up on the right side. If we pick a point on that triangle's face and get the texture coordinates, they are:
0.195789, 0.917363
Now, since I believe that these coordinates are page-based, we can translate these values into tile coordinates:
1.566313, 7.338906
Tile 1, 7 is displayed on the debug overlay. So far, so good. The page is (4,2), which can be verified in the debugger.
Lets see what is known about this page. I have a split heightmap, and I have a split texture index. Opening these in Photoshop I see they are in agreement, and the outline of the shore on these files can be visually matched to the rendered terrain. Well, mostly. There is the problem of this rising point on the right of the wireframe: it is not supposed to be there.
Given that pages are 513 pixels wide, the texture coordinates can be translated into texel coordinates (for the index): 99, 468. Using 512 pixels for the calculation does not change the texel for this point, so that isn't the problem.
Both the heightmap png and the index png show this point at sea level.
The terrain generator dumps the following information for this point, and the 8 surrounding points:
adj: (2146,1491)=(98,467) elev=0 tex=0
adj: (2146,1492)=(98,468) elev=0 tex=208
adj: (2146,1493)=(98,469) elev=0 tex=208
adj: (2147,1491)=(99,467) elev=0 tex=0
adj: (2147,1492)=(99,468) elev=0 tex=208
adj: (2147,1493)=(99,469) elev=0 tex=208
adj: (2148,1491)=(100,467) elev=0 tex=208
adj: (2148,1492)=(100,468) elev=0 tex=208
adj: (2148,1493)=(100,469) elev=0 tex=208
(It is likely not important, but texture 0 is dirt and texture 208 is water). The points are displayed in the following order:
147
258
369
That can also be seen from the coordinates listed in the output, but it is easier if we don't have to think too much about that. And again, the center point (5) corresponds to face on the rising triangle.
Each of the points have elevation 0. So, stitching with nearby vertexes should not be accounting for the problem.
The split height map shows that point as having elevation 0. The index says that point should be textured as water. And indeed, it is shown as a nice chunk of water rising up out of the ocean.
Going further, I have instrumented the vertex buffer loading for this tile.
15:19:42: height(98,467) = 0.000000
15:19:42: storing vertex 1722.656250,0.000000,8208.984375
15:19:42: height(99,467) = 0.000000
15:19:42: storing vertex 1740.234375,0.000000,8208.984375
15:19:42: height(100,467) = 0.000000
15:19:42: storing vertex 1757.812500,0.000000,8208.984375
15:19:42: height(98,468) = 0.000000
15:19:42: storing vertex 1722.656250,0.000000,8226.562500
15:19:42: height(99,468) = 0.000000
15:19:42: storing vertex 1740.234375,0.000000,8226.562500
15:19:42: height(100,468) = 0.000000
15:19:42: storing vertex 1757.812500,0.000000,8226.562500
15:19:42: height(98,469) = 0.000000
15:19:42: storing vertex 1722.656250,0.000000,8244.140625
15:19:42: height(99,469) = 0.000000
15:19:42: storing vertex 1740.234375,0.000000,8244.140625
15:19:42: height(100,469) = 0.000000
15:19:42: storing vertex 1757.812500,0.000000,8244.140625
Again, all of the surrounding points are seen as being at elevation 0.
And yet, the wireframe shows the point above 0. What am I missing here?