Sign in to follow this  
lonewolff

Interpolation between pixels

Recommended Posts

lonewolff    1182
Hi guys,

I am part way through coding my own DX9 framework for a simple 2D game.

I have coded with DX9 on and off for a few years now and have been using Game Maker Studio to rapid prototype my game. GM:S is starting to get a bit restrictive, so I am back onto my own engine again.

One thing I am not sure how to do is replicate GM's 'interpolation between pixels' option, which softens the image slightly and has the other benefit of not making lines look jaggy if they are resized to an uneven amount.

I would love to hear any thoughts on how this might be achieved.

Thanks in advance :)

Share this post


Link to post
Share on other sites
Ashaman73    13715

The interpolation of pixels is called filtering and is a standard feature of your video hardware. In 2d games and GUIs you often want to avoid the softening and a 1:1 mapping. In this case you would sample the texture with nearest-filter (take the pixel values at the nearest texel position). The often used, and standard filtering in 3d games, is the linear filtering, which interpolate the pixel value depending on the 4 neighbor texels. Further on, if you have mipmapping (you want to scale your image down without flickering artifacts), then the hardware will interpolate not only the values of a single texture, but of two neighbor mipmap layers (a mipmap is a downsampled version of the same texture). This is standard, when using hardware rendering and comes at no costs.

 

In fact, even if coding only a 2d game, you use the 3d rendering capability of the hardware (z-coord is fix), just render your 2d sprites as 3d quads with fixed z-coord.

Edited by Ashaman73

Share this post


Link to post
Share on other sites
lonewolff    1182
Thanks for your reply. Makes sense :)

So with the sampling, is this something you can just instruct directX to do or would you have to apply a shader to do this?

Thanks again for your help :)

Share this post


Link to post
Share on other sites
Ashaman73    13715


So with the sampling, is this something you can just instruct directX to do or would you have to apply a shader to do this?

No shader needed, it was one of the first hardware supported features and DX9 will have all support you need out-of-the-box, it is most likely only a simple flag you need to set. Best to start here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this