- July 21, 2011 at 8:26 pm #30583
I’ve recently been working on creating a CUDA based version of the PVR compressor. I’m really close to being done but my compressed images seem to have these weird bright spots that show up. The spots are in different places every time I do the compression and I’m really at a loss for how to get rid of them. From what I can tell it seems that during the optimization of the A and B representative images, the colors go out of bounds – either they become negative or greater than 255. I’ve tried bounding the colors but that just leaves me with white spots instead of colored spots. I’ve also tried replacing the color with that of the original image but that ends up blurring the entire image slightly, but enough so that it’s noticeable. I’ve uploaded the original images and my compressed images and included the links below. You should be able to open the PVR files with the PVRTexTool.
Original Image (lorikeet):
GPU Compressed Image(lorikeet):
Original Image (lena):
GPU Compressed Image(lena):
I’ve been following the PVR paper (https://www.imgtec.com/powervr/insider/docs/PVRTextureCompression.pdf) almost exactly. The only deviation that I’ve made is that I use a matrix of size 49×2 instead of 121×8 during optimization. Since I’m using a GPU, I’ve found that running the SVD on more threads with smaller matrices works faster. The other obvious solution would be to just use the old optimized color value if the new one seems funky but because of the way I’ve laid out the data, this would require otherwise unnecessary extra storage so that’s going to be my last option if nothing else works.
Anyway if anyone has any ideas on how to fix the issue, I would really appreciate it. My version hasn’t really been optimized but it’s already about 10x faster than the one in the PVRTexLib and I plan on making my source code available once I’m finished with it. So the sooner I can sort this bug out, the sooner I can make it available.
EDIT: updated image links
jynnantonix 2011-07-25 23:16:53July 25, 2011 at 5:10 pm #34998
(very HHGTTG BTW),
Yes, the compressor described in the paper originally used SVD to update the representative colours, but I ran into the problem that, if the modulation values used to create the matrix were far from ideal (which would often happen if the original guesses weren’t great) the calculated colours could go a bit crazy. Also, the fact that you could still get an underconstrained matrix was a nuisance.
The current PVRTexTool uses a different approach altogether and that, in turn, is soon to be replaced by a “3rd generation” technique.
Having said all that, there may be a couple of things you can try. You may already be doing this but, for the local 7×7 neighbourhood of pixels, only put the error/differences between the current approximation and the source values into the 49*RGBA vector. Using SVD you should then be able to compute two “updates” to apply to the current central representatives. Also, don’t allow it to step too far in one go as that may be indicative of a poor initial guess.
PS: Any chance of OpenCL instead of CUDA? 🙂July 25, 2011 at 5:24 pm #34999July 25, 2011 at 11:38 pm #35000
It seems filedropper has a limit on how long they will host files. I’ve updated my post with links to the images on my google docs page.
I tried what you suggested – calculating an update to the representative values rather than completely new values and it did get rid of the spots I was talking about. However, the image didn’t look nearly as good as it did before (not including the spots). I think this has more to do with my initial wavelet filter than anything else since the updates will be applied to it. So I’ll be messing around with different filters to see what I can get.
I also implemented what I mentioned in my first post, just re-using the old representative value if the new one is out of bounds. This seems to be working pretty well. It’s not as crisp as the PVRTexLib version but it’s really close.
One question I did have is regarding the values that go into the Mw matrix. The paper says that the values of the matrix are a combination of the distance and modulation value of each pixel in the local block. I haven’t been able to figure out how I should combine the distance; nothing I’ve tried has really worked so my Mw matrix currently only has the modulation value for each of the pixels. Do you think this would make a difference?
And I’ve never actually used OpenCL before. I’m using CUDA now because the compressor is going to be incorporated into a bigger project, much of which also uses CUDA. But I think once I’m satisfied with my version it wouldn’t be too hard for me to write it in OpenCL to allow either option.
Lorikeet with pixel update fix:
jynnantonix 2011-07-25 23:40:40July 26, 2011 at 2:10 pm #35001jynnantonix wrote:It seems filedropper has a limit on how long they will host files. I’ve updated my post with links to the images on my google docs page.
Thanks. I’ll take a look.Quote:I tried what you suggested – calculating an update to the representative values rather than completely new values and it did get rid of the spots I was talking about. However, the image didn’t look nearly as good as it did before (not including the spots).
Curious. The current (2nd gen) and upcoming 3rd gen compressors both use a “correct the error” approach and it seems to work quite well. You will need to run a few update passes though.Quote:One question I did have is regarding the values that go into the Mw matrix. The paper says that the values of the matrix are a combination of the distance and modulation value of each pixel in the local block. I haven’t been able to figure out how I should combine the distance; nothing I’ve tried has really worked so my Mw matrix currently only has the modulation value for each of the pixels. Do you think this would make a difference?
Oh, it should make a big difference.
For the sake of simplicity in the following, let’s just stick to the 4bpp case. AFAIU, you are taking pixel windows that are 7×7 in size and centred on locations of the form [i*4 + 2, j*4 + 2]. Because the underlying upscale is a 4×4 bilinear, you’ll need to scale your weights accordingly.
Now, assuming you are using the “correct the error” approach I suggested, the values for top left pixel (or any corner for that matter) of your window would be weighted by 1/16, i.e. an X weight of 1/4 * a Y weight of 1/4. The next pixel along the top row would be 2/16 (2/4 * 1/4). The very centre pixel would have a weight of 1, and it’s immediate left, right, top and bottom neighbours all have weights of 3/4. I hope that makes sense.
You then combine these ‘distance’ weights with the blend ratios of the mod values to produce each pair of values in your 49×2, Mw matrix.Quote:And I’ve never actually used OpenCL before. I’m using CUDA now because the compressor is going to be incorporated into a bigger project, much of which also uses CUDA. But I think once I’m satisfied with my version it wouldn’t be too hard for me to write it in OpenCL to allow either option.
That’s fair enough. I only ask because OpenCL will (or should eventually) be on a larger set of platforms.
SimonF 2011-07-26 17:53:40July 29, 2011 at 12:47 am #35002
So the distance weight was the thing I was missing. Using a correct the error approach and the matrix set up like you suggested, I’ve gotten my images to look almost exactly like the ones created by the PVRTexLib. With one exception – there seems to be some sort of ‘wrinkling’ effect on the borders of my compressed images. I can make the wrinkles move around to different parts of the image but I can never seem to get rid of them. I’ve figured out that it has something to do with the weight matrix, the bilinear upscale, and the index of the top left pixel in my 7×7 window. Maybe I’m not centering the pixels properly when I upscale because it seems like the three are just very slightly off in one direction or the other and it’s made the past two days really frustrating because I’m so tantalizingly close to having it done. If you’ve run into this problem or have any ideas on what might be causing it, that would be really helpful.
Optimizing pixel pair [i, j]. I run 100 optimization passes to make the effect more obvious because the wrinkles seem directly tied to the number of optimization passes.
Index of top left pixel in 7×7 window [4*i, 4*j]:
Index of top left pixel in 7×7 window [4*i+1, 4*j+1]:
Index of top left pixel in 7×7 window [4*i+2, 4*j+2]:
Index of top left pixel in 7×7 window [4*i+3, 4*j+3]:
Index of top left pixel in 7×7 window [4*i-1, 4*j-1]. This is actually really close to the original if I only run a few optimizations but when I run more, you can see that the problem hasn’t really gone away:
Index of top left pixel in 7×7 window [4*i-2, 4*j-2]:
Index of top left pixel in 7×7 window [4*i-3, 4*j-3]:
Pastebin to my bilinear resize method:
http://pastebin.com/AFN85Sf1July 29, 2011 at 9:32 am #35003
Assuming the top left pixel of the image is 0,0 then the top left pixel of any of your 7×7 windows should be at [4*i – 1, 4*j – 1]. Note that the image is toroidal so the top wraps around to bottom and the left edge wraps with the right.
Now I had a quick look at 2 of your images (the
[4*i – 1, 4*j – 1] and [4*i, 4*j]) and I agree that they are weird. At a guess, it appears some sort of ringing/oscillation starts up and just gets worse and worse – like a positive feedback loop.
In what order do you process the windows and do you update the representatives for the windows sequentially or do you, effectively, do all of them in parallel? Do you fully optimise one region before moving on to the next, or do process the whole image in several passes?
SimonF 2011-07-29 09:34:43August 8, 2011 at 10:52 pm #35004
I figured out the issue. My bilinear upscale wasn’t centering the image properly and that was throwing everything else off. The compressed images look great now.
Thanks so much for your help 🙂November 9, 2011 at 2:41 am #35006
I have a question for you:
is it possible for you to share your GPU compressor?
I’m currently working with a large amount of textures to be compressed, and the process takes hours!
Having a GPU compressor would increase my compression time.
Even if you are not able to share your compressor, could you at least show a comparison in between compression times with one tool or the other?
Thanks in advance!