   Stretching a texture across an entire mesh?
  I currently have a terrain mesh that contains texture coordinates to shade the terrain mesh.  The textures apply fine ( approx 100x100 tiles ) but I'm needing to stretch a single blend texture ( to be alpha blended on top of the already textured mesh ) across the entire mesh to blend the terrain tiles together.  I can't seem to figure out how to get passed the texture coordinates of each tile when I try to apply the splat across the entire mesh - instead it tiles the splat texture in each cell.How can I do this?Thanks!Here's the code that tiles the splat instead of stretching it across the entire mesh.device3D->SetTexture( 0, alphatex[counter] );  //The alpha splat texture to be stretcheddevice3D->SetTexture( 1, m_pTextures ); //The color/texture to blend// Alphamap: take the alpha from the alphamap, we don't care about the colordevice3D->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);device3D->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);// Texture: take the color from the texture, take the alpha from the previous stagedevice3D->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);device3D->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);device3D->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);device3D->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);m_pLocalMesh->DrawSubset( i );
  You need two sets of texture coordinates per vertex: one for the tiled texture, one for the splat.It may be more complicated than you want, but you can do it using a shader.If you can use a shader, here's a quick idea of what's involved.Set up your vertex format to include 2 tex coords. When you load the mesh vertex buffer, set the first tex coord to the tiled texture coord and the second tex coord to the coords you want for the splat.In the shader, set up two samplers: one for the tile texture (S0), one for the splat (S1).In the vertex shader, just pass the 2 texture coords to the pixel shader.In the pixel shader, do something like:    float4 t1 = tex2D( S0, tileCoord );    float4 t2 = tex2D( S1, splatCoord );// alpha blend using the splat alpha    t1 = (1-t2.a) * t1;    t2 = t2.a * t2;    return  (t1 + t2); // the color is the sum of the two colors;  Thanks!The terrain generation program I use sets up the tile coordinates, and I'm not sure how I would calculate the splat coordinate across all the tiles without causing seams or distortion.  Is there a function to have it autocalculate the new texture coords, or do I need to take 1 divided by the terrain coordinate width or height then multiply that by each vertex world coordinate to come up with the new texture coordinate ( 0 to 1 )?Something like this:struct D3DVERTEX{    D3DXVECTOR3 world;    D3DXVECTOR3 normal;    FLOAT  tu1, tv1;    FLOAT  tu2, tv2;};float worldX = 5000.0f;float worldZ = 5000.0f;float modifierX = 1.0f / worldX;float modifierZ = 1.0f / worldZ;import mesh then for each vertex:mesh.tu2 = mesh.world.x * modifierX;mesh.tv2 = mesh.world.z * modifierZ;Is that even remotely close?  hehThanks again!   ;  If you want the splat to extend across the entire terrain, you've got it correct. And congrats on figuring it out!The way you have it set up, you have texcoords for both the terrain texture and the splat. While you're at it, if you can afford a little extra memory, add in a couple more texture coordinates now for possible later use.Here's why:If you're going to implement it using a shader, you can get fancy with your splat texture and use just portions of it at various places over the terrain. If you've got a decent graphics editor (e.g., Photoshop), divide up the splat into several areas, but still all in one texture. Use a gradient in the alpha channel to "feather" the edges of each portion - like water, dirt, rock, etc., so they can be blended onto the terrain texture without ugly edges.Then you can apply dirt to one part of the terrain by setting the second set of texture coordinates to pick out the dirt portion of the splat and blend it into the landscape. Use a third set of coords to blend some water into the low parts of the terrain. The advantage of doing something like that is that the splat texture can be much smaller.In a terrain editor I wrote, I store 4 sets of texture coords for each vertex. The first set (like yours) is for the main terrain texture. The other three are used to pick out portions of a single splat texture which has areas for water, dirt, rock, etc. The splat is 64x256 with 4 64x64 areas but can be applied anywhere over the mesh.If you add the extra texture coordinates to your vertex format now, you can just ignore them or set them to zero. Then set the alpha in the splat texture at coord (0,0) to 0 and nothing gets rendered.Later on you can use those extra texture coordinates if you want. If not, you've only spent an extra 3 sets of D3DXVECTOR2's per vertex.In general, build flexibility into a program early. It's a lot easier to not use it than try to build it in later.Sounds like you're on your way.   ;  Got it working... then ran into video memory constraints!  hah  Fix one thing and break another!Thanks much!   