Sprite rotation

I have a sprite in a Texture2D, if i draw a frame without rotation, it is printed well, but if i rotate the same frame, i get in the right border, the first column of pixels of the next frame.

this.SpriteBatch.Draw(texture, position, sourceRectangle, color, rotation, originRotation, scale, SpriteEffects.None, layerDeth);

PD: The origin of rotation is (heigth/2,0)

Attaching a screenshot can help, and which platform is this occurring on? OpenGL or DirectX? Linux or Windows?

You have to zoom in the image

DirectX, Windows

Edit: The easy way is to make 1 pixel separation in the frames, but i want to know why this is happening

Hopefully someone can help with this, but that image is not very clear…

I changed the image, you can see the pixels in the borders of the frame

Are you using point clamp?

No, i don’t. I don’t even know what is that.

have a look at this similar post (GDSE link).

It work, but then the image look so ugly when rotated.
The problem is not with other textures, the problem is that is not respecting the sourceRectangle (the region of the texture that will be rendered)

PD: I do not move the camera, and i am rounding all the floats to int to draw.

Try LinearClamp instead of PointClamp. I’m guessing that it is wrapping to the other side of the texture during the linear filter and sampling texels that are black or almost black.

I just saw that you are using a source rectangle, so this is a segment of a larger texture. The dark artifacts will then be the linear filter sampling texels from the neighbouring sprites in the texture. You need to add some transparent padding between sprites in your texture to allow for linear filtering (samples neighbouring texels to provide a smoother result than point sampling).

Ok, what i was doing with other sprites, but ¿should not the SpriteBatch not to use pixel outside of the sourceRectangle that you are indicating? and put alpha pixels outside of the sourceRectangle. Just a suggest.

It is an effect of the GPU and filtering. For each pixel it draws on the screen, it samples the closest pixel in the texture and neighbouring pixels to calculate the value to draw to that pixel on the screen. This smooths out the rotation and movement to avoid the ugly artifacts you saw when trying PointClamp. We cannot tell the GPU to not sample outside of a specific region within a texture. It doesn’t work like that.

That is up to you and how you generate the spritesheet texture. We cannot add any fake transparent padding to a spritesheet texture at runtime.

Transparent or do the padded pixels need to be the color of the neighbour pixel?

Ideally the border pixels of the sprite would be extended into the padding area. This would prevent parts of the sprite hard against the edge of the rect being filtered with transparent pixels and therefore becoming partially transparent themselves.

Who doesn’t love floating point rounding errors mixed with gpu antialiasing under rotation.

Id take konajugames advice

or oppositely stick a -1 on your source width height rectangle.