rate up
0
rate down
Changing Texture Coordinates (DirectX11 30. Heightmap (Terrain))
Hey! I'm trying to apply multitexturing to my height map, but I seem to have problem with the wrapped texture coordinates as the multitexturing is applied to every single tile and not to the whole terrain. So, how could I change the following code where you create the index list and the texture coordinates so the wrapping doesn't apply and the multi texturing can apply as a streched image over the height map? std::vector<DWORD> indices(NumFaces * 3); int k = 0; int texUIndex = 0; int texVIndex = 0; for(DWORD i = 0; i < rows-1; i++) { for(DWORD j = 0; j < cols-1; j++) { indices[k] = i*cols+j; // Bottom left of quad v[i*cols+j].texCoord = XMFLOAT2(texUIndex + 0.0f, texVIndex + 1.0f); indices[k+1] = i*cols+j+1; // Bottom right of quad v[i*cols+j+1].texCoord = XMFLOAT2(texUIndex + 1.0f, texVIndex + 1.0f); indices[k+2] = (i+1)*cols+j; // Top left of quad v[(i+1)*cols+j].texCoord = XMFLOAT2(texUIndex + 0.0f, texVIndex + 0.0f); indices[k+3] = (i+1)*cols+j; // Top left of quad v[(i+1)*cols+j].texCoord = XMFLOAT2(texUIndex + 0.0f, texVIndex + 0.0f); indices[k+4] = i*cols+j+1; // Bottom right of quad v[i*cols+j+1].texCoord = XMFLOAT2(texUIndex + 1.0f, texVIndex + 1.0f); indices[k+5] = (i+1)*cols+j+1; // Top right of quad v[(i+1)*cols+j+1].texCoord = XMFLOAT2(texUIndex + 1.0f, texVIndex + 0.0f); k += 6; // next quad texUIndex++; } texUIndex = 0; texVIndex++; } Clarification: I actually do want to strech an image over the height map, but I don't want the image details to disappear completely. The image will probably be blurry, like it's scaled up. So I simply want the texture coordinates for the heightmap to map something like this (for a 256*256 image): v[i*cols+j].texCoord = XMFLOAT2(0.0f, 256.0f); indices[k+1] = i*cols+j+1; // Bottom right of quad v[i*cols+j+1].texCoord = XMFLOAT2(256.0f, 256.0f); indices[k+2] = (i+1)*cols+j; // Top left of quad v[(i+1)*cols+j].texCoord = XMFLOAT2(0.0f, 0.0f); indices[k+3] = (i+1)*cols+j; // Top left of quad v[(i+1)*cols+j].texCoord = XMFLOAT2(0.0f, 0.0f); indices[k+4] = i*cols+j+1; // Bottom right of quad v[i*cols+j+1].texCoord = XMFLOAT2(256.0f, 256.0f); indices[k+5] = (i+1)*cols+j+1; // Top right of quad v[(i+1)*cols+j+1].texCoord = XMFLOAT2(256.0f, 256.0f); Now if I replace these lines and apply your solution: int texUIndex = 0; int texVIndex = 0; with float texUIndex = cols * 0.5; float texVIndex = rows * 0.5; and then in the fragment shader replace the texture coordinates with: vec2 tileSize = TexCoords * 80.0; I could actually get the results I want.
Chosen Answer
rate up
0
rate down
Rather than adding 1 to the u and v coordinates per quad, add an increment value of 1/rows and 1/cols std::vector<DWORD> indices(NumFaces * 3); int k = 0; int texUIndex = 0; int texVIndex = 0; float texUIncrement = 1.0 / cols; float texVIncrement = 1.0 / rows; for(DWORD i = 0; i < rows-1; i++) { for(DWORD j = 0; j < cols-1; j++) { indices[k] = i*cols+j; // Bottom left of quad v[i*cols+j].texCoord = XMFLOAT2(texUIndex, texVIndex + texVIncrement); indices[k+1] = i*cols+j+1; // Bottom right of quad v[i*cols+j+1].texCoord = XMFLOAT2(texUIndex + texUIncrement, texVIndex + texVIncrement); indices[k+2] = (i+1)*cols+j; // Top left of quad v[(i+1)*cols+j].texCoord = XMFLOAT2(texUIndex, texVIndex); indices[k+3] = (i+1)*cols+j; // Top left of quad v[(i+1)*cols+j].texCoord = XMFLOAT2(texUIndex, texVIndex); indices[k+4] = i*cols+j+1; // Bottom right of quad v[i*cols+j+1].texCoord = XMFLOAT2(texUIndex + texUIncrement, texVIndex + texVIncrement); indices[k+5] = (i+1)*cols+j+1; // Top right of quad v[(i+1)*cols+j+1].texCoord = XMFLOAT2(texUIndex + texUIncrement, texVIndex); k += 6; // next quad texUIndex += texUIncrement; } texUIndex = 0; texVIndex += texVIncrement; }
Comments
Alright, but the texture seems to loose it's details and simply renders as the plain color of the texture (if I only use one texture). Any ideas about this?
on Aug 14 `16
Keyzzz
yeah, the texels in the texture (pixels in image) will be MUCH larger if you stretch the image across the entire terrain, which is what i thought you were asking to do in your question. I might have misunderstood your question, but it sounded like you wanted to stretch the image across the entire hieghtmap rather than repeat the texture across it for each quad. Maybe you could clarify with an example or a sample image showing what you want exactly?
on Aug 14 `16
iedoc
Sign in to answer!