2
0
Эх сурвалжийг харах

Fix edge bleeding on normal maps, fix off-by-1 on texture coords.

Jim Duchek 10 жил өмнө
parent
commit
29fd7c0f22

+ 1 - 0
gameplay/src/Terrain.cpp

@@ -262,6 +262,7 @@ Terrain* Terrain::create(HeightField* heightfield, const Vector3& scale,
     if (normalMapPath)
     {
         terrain->_normalMap = Texture::Sampler::create(normalMapPath, true);
+        terrain->_normalMap->setWrapMode(Texture::CLAMP, Texture::CLAMP);
         GP_ASSERT( terrain->_normalMap->getTexture()->getType() == Texture::TEXTURE_2D );
     }
 

+ 5 - 2
gameplay/src/TerrainPatch.cpp

@@ -202,8 +202,8 @@ void TerrainPatch::addLOD(float* heights, unsigned int width, unsigned int heigh
             v += 3;
 
             // Compute texture coord
-            v[0] = (float)x / width;
-            v[1] = 1.0f - (float)z / height;
+            v[0] = (float)x / (width-1);
+            v[1] = 1.0f - (float)z / (height-1);
             if (xskirt)
             {
                 float offset = verticalSkirtSize / width;
@@ -419,6 +419,9 @@ int TerrainPatch::addSampler(const char* path)
     // Add a new sampler to the list
     Texture::Sampler* sampler = Texture::Sampler::create(texture);
     texture->release();
+
+    // This may need to be clamp in some cases to prevent edge bleeding?  Possibly a
+    // configuration variable in the future.
     sampler->setWrapMode(Texture::REPEAT, Texture::REPEAT);
     sampler->setFilterMode(Texture::LINEAR_MIPMAP_LINEAR, Texture::LINEAR);
     if (firstAvailableIndex != -1)