Skip to main content
GameDev.net gamedev.net
🔒 Locked

question about how to downsample a texture

Started by champloo Feb 29, 2012 at 7:25 PM 3 replies 3.4k views
Original Post
champloo
champloo
I did some research on downsampling recently but couldn't find a clear answer, it almost feels like everybody thinks it's too simple to mention..
Currently my way of doing downsampling is to draw a smaller textured quad to a smaller render target.
So if I want to downsample my diffuse map which is 1280x720, to a quarter sized texture. I will have to draw a 640x360 textured quad to a 640x360 render target. and I'm not sure if it's the right way.
Also, if I want to render my scene onto a render target of a different size, do I modify the SV_Position inside the shader or change the projection transformation, or is there some other way to do it?
Tsus
Tsus
Hi!

Two options come to my mind.

  1. Generate a single mipmap level and use the load intrinsic to directly fetch from it, during rendering of a half resolution viewport. (GenerateMips will automatically filter and downsample). This is easy to do and can serve as a ground truth.
  2. Use bilinear filtering and sample from the pixel corners (which results in averaging the four neighbor pixels). Here you have to shift your sample positions a little. Also not very difficult, but you could check it against the other approach for correctness.

And then use the one that’s faster. smile.png (Probably option 2)

If you want to use other resolutions you can use trilinear interpolation in your mipmap pyramid. Since GenerateMips applies linear filters, you can safely interpolate between adjacent levels.

Cheers!
Adam_42
Adam_42
If you're doing #2 you can also use a pixel shader that samples more than one source location and combines them. This can get you a 4x, 9x, 16x, ... downsample in one go, which can be faster than using an extra pass, but don't go overboard with the size of the loops in the shader - at some point an extra pass will be quicker.
champloo
champloo
Thanks a lot for your answers. So it seems what I'm doing now is not absolutely wrong.

One more question, do I need to change the viewport everytime I change to a render target of different resolution?
Adam_42
Adam_42
Under DX9 switching render target automatically changes the viewport to match the size of the target. I'd assume D3D10/11 does the same thing, but it doesn't mention it on msdn. It's simple enough to try it and find out though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.