[Solved] Weird Display Issue Using a Rectangle

For the moment I will do a 1 padding pixel between my sprite. Thank for help me : )

Without doing the 1px padding, and while using the Matrix, a solution off the top of my head would be to first draw the sprite at itā€™s original scale to a RenderTarget, then use that RenderTarget as the source texture to draw the scaled up version. That would allow monogame to sample the bleed pixels from the non-existent outside of the sprite without collecting from other sprites. This method would come with a pretty steep performance hit though, Iā€™d assume.

1 Like

Without looking too deeply into your code, I have an idea of what is likely the issue.
Your ā€œsource rectangleā€ is
new Rectangle(0,32,32,32)
and your sprite sheet, Iā€™m guessing, is 64x48? Thatā€™s what it looks like in your image.
Anyway, 32/48 is .666ā€¦, which, when stored as a binary float, actually comes out to be 5592405/2^23, or 0.66666662693023681640625. Notice that this is less than 32/48ā€™s true value. As such, the sampler grabs part of the pixel above.
If this is indeed the issue, one easy way to overcome it is to make your sprite sheet a power of 2 in each dimension (like 64x64), as then it wonā€™t have any awkward ā€œdecimalā€ values to deal with. 32/64, for example, is .5, nice and easy!

Yep clamp only applys to the edges of a texture which means 0 to image Width or in Uv coordinates 0 to 1f meaning the gpu wont sample below 0 or beyond a value of image.Width -1

This means for a sprite sheet setting the uv texture address mode to clamp simply doesnā€™t apply to source rectangles in the middle of a texture reliably without padding between the images.

2 pixels of padding is safer (without going into the whys) where a color like red might work to prove that. Mostly i choose rgba = 0
Most spritesheets simply have that as a background color with sprites that donā€™t fill the whole sprite rectangle. So there is naturally padding but for fully opaque images that fill the entire sprite sheet its easy to forget you need padded lines around the sprite as well.

Also note if you want to use antialising sampling aka linear or ansiostropic and you dont want point sampling this padding should be even wider.

So far the issue was about scaled up sprites without mipmaping and/or anisotropic sampling, but since you brought it up, I have an Atlas/Sprite importer that will import sprites with mipmaping that wont bleed color between sprites. Each sprite is re-sampled individually and the atlas is recombined on each mip level. check it out:
https://twitter.com/nkast/status/865321646449725442

@ed022
The spritesheet is 32*32 pixels.

@nkast Thank you for the Atlas/Sprite importer :slight_smile:, but I also have another software that do the job ^^

After trying several solutions ( like the 2 pixels padding and moreā€¦), I finally choose to use a Render Target for my game. And then each element is render on the Render Target. And by scaling only the Render Target, I avoid this glitch and making a 2 pixels padding between my sprites.

Thank to everyone for helping me with this issue.

Are you sure itā€™s 32x32? That would imply that each individual sprite (in the original picture above) is only 8x8 pixels, and that seems impossible.

Sorry if I wasnā€™t clear, the texture is 256256 and each sprite is 3232, but I dont think that matter