Original Post
I'm writing a terrain shader that deals with a terrain broken up into subgrids and multiple draw calls. Because I have a single large normal map to apply, I supply the texture coordinates as if the whole thing were one big mesh with the intention of scaling down my detail texture coordinates later. I'm having trouble getting my basic texture coordinates right.
int WorldWidth = Parent.TerrainFragmentWidth * Parent.FragmentCount;
int WorldHeight = Parent.TerrainFragmentHeight * Parent.FragmentCount;
int PolyOffsetX = ((Position.X * Parent.TerrainFragmentWidth) + (x % Width)) / WorldWidth;
int PolyOffsetY = ((Position.Y * Parent.TerrainFragmentHeight) + y) / WorldHeight;
Vector2 TextureOffset = new Vector2(PolyOffsetX, PolyOffsetY);
Geometry[x] = new VertexPositionNormalTexture(VertexPosition, Normals[x], TextureOffset); y is the actual position of the vertex in the grid and x is the vertex index. Width is the subgrid width. It should simply align a single instance of the texture to the terrain extents. At the moment my normal map just shows as a huge square of red if I output it as a flat diffuse texture, showing no detail at all. It's either too large, too small or just screwed up in some other way. When I work this out by hand, it seems like it should be correct. What other things am I likely to have done wrong here to cause this?