Interpolation between pixels

Started by
3 comments, last by DividedByZero 10 years ago
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 :)
Advertisement

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.

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 :)


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.

Nice! Thanks for the link :)

This topic is closed to new replies.

Advertisement