Just an aside as it is a couple of days since I posted on this.. but may be useful to future readers:
Although the above algorithm is 100% accurate, it was still a little slow for padding completely all the gutter space on 4096x4096 textures. So I noticed that 99.9% of the time, the best 'source pixel' for the padding is the same source pixel as one of the neighbours in the padding.
Based on that I used a slight variation on the dilate idea:
- Find the edges, for all edge pixels, run 'AddActiveNeighs' function
- AddActiveNeighs adds to an 'active list' any of the 8 nearest neighbours that
Have not been done already
Are not solid pixels in the UV map
[attachment=34528:dilate.png]
- Once this is done you can iterate (as much pixel dist as required) over the active list:
For each pixel in the active list:
- Look out over a specified range (I used 3 pixels out (48 checks)), lookup in a 'source coords' image the best 'source coords' of each neighbour ..
- find the distance to that neighbours best source, and hence find the best source coords out of our neighbourhood selection.
- Add our own best fit to the 'source coords' image.
- Then run AddActiveNeighs again, to add the next iterations pixels to look through. (and remove ourself from the active list).
At the end we have a map of the best 'source coords' for each gutter pixel, allowing very quick dilation when required.
It takes about 4 seconds to run unoptimized on a low end PC for 4096 x 4096 to pad the whole texture, so should be fine to run when loading project files instead of saving it in them. :)