iDevGames Forums
down-sampling textures smoothly - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: down-sampling textures smoothly (/thread-1906.html)

down-sampling textures smoothly - reubert - Jan 17, 2009 12:16 AM

I'm getting a video feed, and wanting to downsample it a lot - to roughly 32x32 pixels. I will then be scaling it up, but want a nice smooth representation.

Basically I want the 32x32 mipmap of a 640x480 image.

So I tried the worst case, rendered the raw feed into a 32x32 FBO, drew the FBO to the screen, and the result is poor. For each FBO pixel it takes a single texel from the large texture, so it's noisy and not averaged in anyway, missing details. (left side of example image)

That's what I expected. So I was ready to setup a 512x512 FBO, a 256x256,128,64,32. Planned to use a shader on each pass to take 4 pixels and average them for the output.

Then I implemented the first stage... rendering the result of each higher resolution FBO into the smaller one, starting at 512x512 read, 256x256 write, and then 256x256 read, 128x128 write... etc. No averaging shader.

And it's perfect. The result is smooth, like a mipmap. (right side of example image)

So what the hell is going on here? Does reading from a texture that has double the texels of the output buffer magically average? Is this maybe unique to nVidia cards? Example images (kind of hard to see the difference, but with moving video it's huge):
[Image: downSample.jpg]

down-sampling textures smoothly - aBabyRabbit - Jan 17, 2009 12:51 AM

It does average if you read from the appropriate texture coords and the texture has linear interpolation set on it.

down-sampling textures smoothly - reubert - Jan 17, 2009 01:07 AM

hmm... so a simple case, grayscale 2x2 texture (with min filter linear interpolation on):
[255, 0,

So now I render that into a quad on a 1x1 FBO. The texCoords are 0,0 bottom left and 1,1 top right. Does that mean that the resulting pixel uses 0.5,0.5 and so interpolates to 128?

Makes sense I guess... Sweet Smile

down-sampling textures smoothly - arekkusu - Jan 17, 2009 09:58 AM

This is a good example of "you should read the documentation" which says:
Returns the weighted average of the four texture elements that are closest to the center of the pixel being textured.

This paper may also be of interest, if you're willing to use hardware-specific features to optimize the downsample.

down-sampling textures smoothly - reubert - Jan 17, 2009 03:32 PM

Cool, thanks guys. It makes perfect sense now.