程序纹理紫外线错误

时间:2018-04-02 23:08:21

标签: c# unity3d procedural-generation uv-mapping

我正在用程序生成的平面和紫外线创建一个游戏,它的工作原理很好,但是有一个地方紫外线看起来很混乱。

简介:uv映射在“全局”uv坐标中,而不是局部坐标,因为纹理必须与相邻平面对齐。每个纹理都有2 * 2的平铺,我引入了2的uv标度,这意味着每个平面“v”坐标将垂直地映射到纹理的范围[0,0.5],以确保水平“u”坐标不超出范围[0,1]。 (水平地,噪声在某种程度上是不可预测的)。 代码:

     Vector2[] CalculateU(float[] leftXMap, float[] rightXMap) {
         int length = leftXMap.Length;
         float totalHeight = (length - 1) * 1;       // distance between two vertices vertically is 1
         float uvheight = totalHeight * uvScale;     // uvScale is 2, purpose is to map a plane's v(vertically), into a range of [0, 0.5]..
         Vector2[] UMap = new Vector2[length * 2];
         for(int i = 0; i < length; i++) {
             float left = leftXMap[i];
             float right = rightXMap[i];
             // make left and right positive.
             while (left < 0) {
                 left += uvheight;
             }
             while(right < 0) {
                 right += uvheight;
             }
             float leftu = (left % uvheight) / uvheight;
             float leftv = (i / (float)(length-1)) / uvScale;
             float rightu = (right % uvheight) / uvheight;
             float rightv = leftv; //(i / (float)length) / 2f;
             UMap[i * 2] = new Vector2(leftu, leftv);
             UMap[i * 2 + 1] = new Vector2(rightu, rightv);

         }
     }

解释: 函数的参数是生成的平面的噪声图。噪音是x坐标。而y坐标是简单值0,1,2,....(长度-1)。

纹理扭曲:

enter image description here

放大:

enter image description here

1 个答案:

答案 0 :(得分:0)

我设法解决了这个问题,紫外线地图在左侧噪点地图值为负值时出现混乱,右侧噪点图为正值。

由于我总是尝试将所有负值映射到正值,因此左侧噪声贴图(也是我的左顶点x坐标)将被映射到正值。但是它会比右边的噪声图(右顶点x坐标)大。然后它弄乱了紫外线。

我完全没有映射解决它,突然意识到UV地图值可能是负数,我根本不需要映射!