简体   繁体   English

我该如何正确将其绘制到UV贴图?

[英]How would I get this to UV map correctly?

Alright so I have my code to draw out a big landscape using C++ and DirectX. 好了,所以我有了我的代码,可以使用C ++和DirectX绘制一个广阔的前景。 I had it textured with one texture and then needed to add more. 我用一种纹理对其进行了纹理处理,然后需要添加更多纹理。 I saw people doing it where they had 1 texture image and the image contained 2 textures. 我看到人们在有1个纹理图像且图像包含2个纹理的地方这样做。 Thats what I made, it's a 256x128 image. 那就是我所做的,这是一个256x128的图片。 My problem now is that since my terrain automatically generated the coordinates to UV map 1 texture now it is displaying both textures. 现在的问题是,由于地形自动生成了UV贴图1纹理的坐标,因此它同时显示了两个纹理。 I need to make it so when the height of the world is high enough it is 1 texture and everything under is another texture. 我需要做的是,当世界的高度足够高时,它是1纹理,下面的所有东西都是另一纹理。 My code for the UV coordinates, 我的UV坐标代码,

Vertices[y * WIDTH * x].U = x / 1.28; 顶点[y *宽度* x] .U = x / 1.28;

Vertices[y * WIDTH * x].V = y / 1.28; 顶点[y *宽度* x] .V = y / 1.28;

those are my mapping coordinates, X is the current X value of the vertice it is drawing and the Y value is its current y position. 这些是我的贴图坐标,X是它正在绘制的顶点的当前X值,Y值是其当前y位置。 The heightmap is 128x128 so I divided by 1.28 to make it so that each polygon had the texture UV mapped on it. 高度图为128x128,因此我将其除以1.28,以使每个多边形上都具有UV贴图。 The height is calculated as well since I am loading a heightmap and im trying to get it so when it is high enough it UV maps 1 half of the image and if it is the other it UV maps the other side of the image. 高度也是计算得出的,因为我正在加载一个高度图并尝试获取它,因此当高度足够高时,UV会映射图像的一半,如果另一高度,则UV会映射图像的另一侧。 Someone please help! 有人请帮忙!

bool topTexture = height[x][y] > threshold;
float u = x / 1.28;
float v = y / 1.28;
Vertices[y * WIDTH * x].U = (u - (int)u) / 2 + (topTexture ? 0.5 : 0);
Vertices[y * WIDTH * x].V = (v - (int)v) / 2 + (topTexture ? 0.5 : 0);

You may want to blend the two textures at the threshold level. 您可能需要在阈值级别混合两个纹理。 Then, you have to do it in the PixelShader. 然后,您必须在PixelShader中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM