Wednesday, March 11, 2015

Seamless tiling on fixed height map


I managed to find this bit of code for seamlessly tiling using a noise algorithm.
Ftileable(x, y) = (
       F(x, y) * (w - x) * (h - y) +
       F(x - w, y) * (x) * (h - y) +
       F(x - w, y - h) * (x) * (y) +
       F(x, y - h) * (w - x) * (y)
) / (wh)
or basically a correlated statistical weighting with coordinates.  In the algorithm, one need supply coordinates to a choice noise algorithm.  

In this case I were looking for a slight modification say when using textures with corresponding heightmaps either having more data intense procedural computations or neither having coupled noising procedure.  

In this case one would need to replicate some manner of periodicity of the texture heightmap tile at the given edge boundary.  

For instance on a height map with localized  u v coordinates with 513x513 positions.  
The position (0,0) would need be matched to a texture tile at position (512,0) as a left neighbor, position (0,512) for a given bottom tile neighbor, and (512,512) for the bottom left neighbor tile.  

Or in generalized coordinates (-512,-512), (-512,0), (0,-512) would need be matched.  

To produce periodicity of the texture then one could use simple flip algorithms on the tile so that the noise were periodically matched.  

In this case, 

180 rotation is top bottom flip with lr flip. (x,-y)
left right flip is (-x,y)
applying lrflip to tpbtm coord -xtb, ytb is tblr flip or pure 180 rotation is lrtb flip (-x,-y)
F(x-w,y) uses lr flip, F(x,y-h) uses tb flip, F(x-w,y-h) uses lrtb flip 

An excerpt of my code would then look as follows when iterating over the set of height map points:
   terr::Coordpair hcoord = (*i).first;
   int xpos = hcoord.first;  int ypos = hcoord.second;
   int xposp = xpos-512;  int yposp = ypos - 512;

   terr::Coordpair * hcoord1 = new terr::Coordpair(-1*xposp, ypos);
   terr::Coordpair * hcoord2 = new terr::Coordpair(xpos, -1*yposp);
   terr::Coordpair * hcoord3 = new terr::Coordpair(-1*xposp, -1*yposp);
   double val1 = (*combinevals)[hcoord]*((double)(512-xpos))*((double)(512-ypos));
   double val2 = (*combinevals)[(*hcoord1)]*((double)(xpos))*((double)(512-ypos));
   double val3 = (*combinevals)[(*hcoord2)]*((double)xpos)*((double)ypos);
   double val4 = (*combinevals)[(*hcoord3)]*((double)(512-xpos))*((double)ypos);
   double height = (val1+val2+val3+val4)/(512.0f*512.0f); 





Example result shown above.

Another potential simple method also uses flips on a given map combining all maps into say a 1026 x 1026 map and then re sizing the height map down to 513 x 513 (or a maps original size).  This, however, I imagine includes resolution loss in height data.

Either of these methods tend to produce very symmetric looking noise maps.

No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...