Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: fragment shader 2-3 pixels missing causing unwanted offset/aligning  (Read 2176 times)

0 Members and 2 Guests are viewing this topic.

Predator106

  • Newbie
  • *
  • Posts: 43
    • View Profile
I'm not sure where this is, but the only thing i can think of the problem existing in, is within the fragment shader. i pass it a row of 16x16 textures whcih are the tile_types_super_texture, and then a pixel representation of that tilemap. but my tilemap is actually visibly a couple pixels below (y) of where it should be. here's a screenshot http://wstaw.org/m/2012/12/05/plasma-desktopI21411.png

the crosshair is fine and is locked at 16x16 increments. i thought perhaps my view is off by 2 pixels or something..but that strikes me as odd as well/not possible.

i wanted to try and render the result and save that as an image, to see if the shader is in fact the issue..but i wasn't sure how to do that.

and just to make sure it wasn't my crosshair's alignment, i pushed the tilemap all the way to the top, and there's a 2px remaining from what is a tile that should be off the screen (above the top of the screen).

is there some issue here with me casting to integer, do you think? i'm kind of lost, and a bit disheartened because i thought my tile map was working perfectly, and here it's some odd problem.

i'm not even sure if it's not a driver issue..if somebody could also test this out, it probalby only builds on linux, but should be pretty easy to build there since it uses cmake. sfml 2.0 of course: https://github.com/sreich/buildarrhea

or maybe you can suggest something?

#version 130

//for a 1600x900 screen, this results in an image of 50x100 with each pixel representing a tile
uniform sampler2D tilemap_pixels;
//a runtime generated spritesheet of all tiles we know, each tile being 16x16 (so 48x16 if there are 3 tile types)
uniform sampler2D tile_types_super_texture;

//FIXME: stop hardcoding ..
ivec2 TILE_SIZE = ivec2(16, 16);

void main()
{

    ivec2 tilemap_size = textureSize(tile_types_super_texture, 0);

    ivec2 screen_coordinates = ivec2(gl_FragCoord.x, gl_FragCoord.y);

    // find the pixel (RGBA) values in the tilemap pixel representation that is what we're
    // currently interested in.
    vec4 currentPixel = texelFetch(tilemap_pixels, screen_coordinates / TILE_SIZE, 0);

    ivec2 tileCoordinate;
    tileCoordinate.x = (int(currentPixel.r * 255.0) ) * TILE_SIZE.x + (screen_coordinates.x % TILE_SIZE.x);
    tileCoordinate.y = screen_coordinates.y % TILE_SIZE.y;

    vec4 tileColor = texelFetch(tile_types_super_texture, tileCoordinate, 0);

    gl_FragColor = tileColor;
}

Predator106

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: fragment shader 2-3 pixels missing causing unwanted offset/aligning
« Reply #1 on: December 05, 2012, 07:20:52 pm »
huh. my shader is working just fine, at least when i save the output to a file.. interesting.

Predator106

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: fragment shader 2-3 pixels missing causing unwanted offset/aligning
« Reply #2 on: December 05, 2012, 09:58:59 pm »
oh nvm, my shader is screwed up. after a while of poking around, i think i'm just going to try it without a shader.