Nearest Point Sampling: artifacts
Hello,
I want to draw some 2d sprites with Direct3D (DX9) using RHW-Vertices. I am using Nearest Point Sampling. When the sprite overlaps on the upper or left bound of the screen some artifacts appear. It looks bad! I've taken a screenshot:
I've found an article about Nearest Point Sampling in the MSDN:
Nearest Point Sampling
But I don't understand how to avoid these artifacts. Can you help me, please!
[edited by - SlimTimmy on November 15, 2003 10:18:25 AM]
[edited by - SlimTimmy on November 15, 2003 10:26:06 AM]
[edited by - SlimTimmy on November 15, 2003 10:28:13 AM]
Add 0.135 pixels to all the vertice's positions x and y. The artifact is probably a result of inaccurate conversion of the floating-point position to integers.
-Nik
EDIT: A related issue: Your gfx driver may have the setting of how it considers the pixel's sample center point (ie. is it top-left or center). Try to adjust that setting first to confirm the cause.
[edited by - Nik02 on November 15, 2003 10:24:39 AM]
-Nik
EDIT: A related issue: Your gfx driver may have the setting of how it considers the pixel's sample center point (ie. is it top-left or center). Try to adjust that setting first to confirm the cause.
[edited by - Nik02 on November 15, 2003 10:24:39 AM]
quote:Original post by Nik02
Add 0.135 pixels to all the vertice''s positions x and y. The artifact is probably a result of inaccurate conversion of the floating-point position to integers.
He''s sampling at the edge of texels, so it''s just a matter of ''luck'' what texel will actually be read. What''s 0.135 got to do with it?
quote:A related issue: Your gfx driver may have the setting of how it considers the pixel''s sample center point (ie. is it top-left or center). Try to adjust that setting first to confirm the cause.
All cards sample at the center by default. You should not try to modify it. Just position the sprite correctly by subtracting 0.5 from every x and y component so that pixel centers correspond to texel centers.
Since actual pixels are at integer intervals, the natural inaccuracy of the floating-point position''s conversion to ints causes the card to "guess" the positions between 2 nearest choices.
Now, adding or subtracting some fraction of the pos makes it clearer to the card in what pixels it should take from which points.
-Nik
Now, adding or subtracting some fraction of the pos makes it clearer to the card in what pixels it should take from which points.
-Nik
quote:Original post by C0D1F1ED
He''s sampling at the edge of texels, so it''s just a matter of ''luck'' what texel will actually be read. What''s 0.135 got to do with it?
I remember to have read this figure somewhere, but you''re right: The actual value shouldn''t affect the perceived position, as long as the value <= 0.5f.
Note that in multisampling scenario, you should divide the value by the square root of the number of samples to compensate for the subsample positioning.
-Nik
quote:Original post by C0D1F1ED
All cards sample at the center by default. You should not try to modify it. Just position the sprite correctly by subtracting 0.5 from every x and y component so that pixel centers correspond to texel centers.
That''s OpenGL''s behaviour. DX is different. Texels are sampled exactly where you say. 0,0 is the corner, not the center, of the first pixel. Either add 0.5f/imagesize to the texture coordinates, or move the vertex by half a pixel (as was mentioned above).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement