0
\$\begingroup\$

I noticed that render a portion of the texture, upscaling it, it affects is border values with the proximity of the outside remaining parts of the texture (when not using Neareast neighbour interpolation)

This is a problem when those 2 portions are 2 different frames: basically it is interpolating the border with the outside of the texture when need rescaling.

This causes frame/sprite artifacts.

Consider a texture atlas with multiple frames next to each other. Copying one frame is resulting having the border interpolated with another frame and this most likely is creating an artifact.

Is there any way to strictly render a portion of texture making SDL Renderer ignoring whatever else is outside the rect?

Simply copy and rescale only the rect given?

e.g: The 2 frames: enter image description here

1st frame on the bottom is altered by the values of the 2nd frame enter image description here

2nd frame on the top is altered by the values of the 1st frame enter image description here

This issue doesn't happen if adding 1 pixel pad among the 2 frames or using 1 texture per frame. I am wondering is there any SDL2 settings to avoid this unwanted (subpixels?) interpolation?

Please also note that all the operations are performed with exact integers, so don't understand really from where that "noise" could come from. Could it be from some Video drivers settings?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Do you have access to Array Textures? If your images are all one size (or you have a few common sizes, one per array), this lets you stack them on layers rather than side-by-side, and the layers don't blend into one another. \$\endgroup\$
    – DMGregory
    Nov 22, 2023 at 13:32
  • \$\begingroup\$ i have also created a way to do array texture, in the term 1 frame <-> 1 texture and storing many textures as many frames. Is that what you mean with array textures? Is there any performance penalty switching texture very often compared to having a texture-atlas? \$\endgroup\$
    – Raffaello
    Nov 22, 2023 at 15:30
  • 1
    \$\begingroup\$ No, that's an array of textures. An array texture is a single texture with several layers that function like separate images, but can be indexed from a single sampler on the GPU, so it doesn't break batching when you need to switch layers — similar to an atlas, but without blending at the edges between images in the atlas. The constraint is that all layers must have the same dimensions. \$\endgroup\$
    – DMGregory
    Nov 22, 2023 at 16:11
  • \$\begingroup\$ i see, that's what i was looking for, unfortunately SDL2 doesn't have nor support anything like that: I have to start migrating/move away from SDL2, at least partially. \$\endgroup\$
    – Raffaello
    Nov 22, 2023 at 22:52

1 Answer 1

0
\$\begingroup\$

The problem exists when not using Nearest Neighbors interpolation and upscaling textures.

I have solved this problem creating a padding around each frame of 2 pixels when loading and composing the texture atlas and added the padding when retrieving the frame area. Even though 1 pixel could be enough, but in general could be N pixel(s) depending on the case.

On the other hand it requires a little more memory to store all the frames.

An alternative could be to use 1 frame per texture eventually.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .