Jump to content
  • Advertisement
Sign in to follow this  
champloo

question about how to downsample a texture

This topic is 2476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!