1
\$\begingroup\$

I'm trying to implement a faster alternative to super-sampling for my isometric 2d monogame game (for when the view is zoomed out). The idea was that I would render the texture coordinates to the render target like so :

output.Color = float4(input.TexCoord.xy, 0, 1);

render-target with texture coordinates as output

And then I would sample the sprite using the surrounding pixels' texture coordinates to get an anti-aliased color. I first tried my method by only sampling the original pixel to see if I could replicate the original output first but I can't make it work. This is the result I get :

output.Color = sprite.Sample(spriteSampler, tex.Sample(texSampler, input.TexCoord).xy);

render-target with colors sampled from the sprite using the previous render-target

I use point filtering, I tried disabling mipmaps I tried offsetting the texture coordinates, it just doesn't work. For some reason the sampled texture coordinates are linearly interpolated, which gives out nonsense texture coordinates at the edges of textures producing black lines.

However if I zoom in closely enough and align the camera somewhat I get the correct output :

render-target with colors

So what is causing those black lines? What can I do to remove them?

Additional info

Sprite dimensions : 2048 x 2048

Render target format for texcoords : Vector2

Vertex declaration for the screen quad (not indexed) :

vertices = new VertexPositionTexture[6];
vertices[0].Position = new Vector3(-1, 1, 0);
vertices[1].Position = new Vector3(1, 1, 0);
vertices[2].Position = new Vector3(-1, -1, 0);
vertices[3].Position = new Vector3(1, 1, 0);
vertices[4].Position = new Vector3(1, -1, 0);
vertices[5].Position = new Vector3(-1, -1, 0);

vertices[0].TextureCoordinate = new Vector2(0, 0);
vertices[1].TextureCoordinate = new Vector2(1, 0);
vertices[2].TextureCoordinate = new Vector2(0, 1);
vertices[3].TextureCoordinate = new Vector2(1, 0);
vertices[4].TextureCoordinate = new Vector2(1, 1);
vertices[5].TextureCoordinate = new Vector2(0, 1);

This is the code that converts the the computed coordinates for the blocks to screen space :

float4 PixelToScreen(float4 position)
{
    position.x = position.x * ((scale * 2) / resolution.x) - 1;
    position.y = position.y * ((scale * 2) / resolution.y) + 1;

    return position;
}
\$\endgroup\$
  • \$\begingroup\$ How big is the texture you're sampling from? What format is the render texture you're writing your texture coordinates into? Can you show us your code so we can check details like how you've ensured 1:1 pixel to texel alignment between your passes? \$\endgroup\$ – DMGregory Jul 7 at 21:37
  • \$\begingroup\$ @DMGregory I added some info \$\endgroup\$ – wingmanx7 Jul 7 at 23:34
0
\$\begingroup\$

One answer is padding your sub textures with zero alpha for the near misses in sampling. You can also use glSetTexParameterI(GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE) or something similar (sic)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.