Map Your Texels to Pixels!
Thursday, 6. March 2008, 21:42:06
Directly Mapping Texels to Pixels.
The main problem is, that when texels are not aligned to pixels, Linear filtering blurs the texture and it ends up looking ugly(a bit more info than the msdn article).
Another problem is that the is image is slightly offset. By 0.5 texels to be exact. This isn't really a problem if the resolution is high. But what happens if you want to stretch a low res texture on the entire screen?
Bloom is a perfect example: render something a small texture (128x128), blur it vertically (render to another 128x128 texture), blur the result horizontally (render to a 128x128 texture), stretch the result over the screen.
If you aren't aligning texels to pixels, the image is "slightly" offset three times. But surely that can't add up to anything noticeble?!
O RLY..? ("And don't call me Shirley"
)
Without alignment:
With alignment:
(Yes, the red circle thingy is blooming green, it's just to make the problem more visible)
As the articles state, all you have to do, is offset the vertices (or texture coordinates) by half a texel:
Pos-= 1.0/ textureSize* 0.5;
So if your render target is 800x600 and your texture is 128x128 you need to do
Have a nice day.
The main problem is, that when texels are not aligned to pixels, Linear filtering blurs the texture and it ends up looking ugly(a bit more info than the msdn article).
Another problem is that the is image is slightly offset. By 0.5 texels to be exact. This isn't really a problem if the resolution is high. But what happens if you want to stretch a low res texture on the entire screen?
Bloom is a perfect example: render something a small texture (128x128), blur it vertically (render to another 128x128 texture), blur the result horizontally (render to a 128x128 texture), stretch the result over the screen.
If you aren't aligning texels to pixels, the image is "slightly" offset three times. But surely that can't add up to anything noticeble?!
O RLY..? ("And don't call me Shirley"
Without alignment:
With alignment:
(Yes, the red circle thingy is blooming green, it's just to make the problem more visible)As the articles state, all you have to do, is offset the vertices (or texture coordinates) by half a texel:
Pos-= 1.0/ textureSize* 0.5;
So if your render target is 800x600 and your texture is 128x128 you need to do
Pos-= 1.0/ 128.0* 0.5;
Have a nice day.
"Pos-= 0.5/128.0;" looks simpler. And you don't have to do this in D3D10 anymore.
By anonymous user, # 7. March 2008, 01:32:48
The last post was mine
By anonymous user, # 7. March 2008, 01:33:41
By nerius, # 7. March 2008, 11:57:59