GMS 2 Slight Sprite/Texture Glitch

Discussion in 'Programming' started by Anixias, Nov 8, 2018.

  1. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    165
    Hi. I decided to optimize how I render my game's terrain. The terrain is tile-based. I was simply looping through every tile on screen every frame and recalculating subimages and rendering tiles. As you can imagine, this didn't really work, as it took 95% of my debugger's profiling time.

    So, I made the switch to Vertex Buffers. I used sprite_get_uvs, etc. and got it all rendering 100% perfectly minus one small glitch: There is a grid where it isn't reading colors.

    Here is a picture of what I'm talking about:
    [​IMG]

    Notice how the water underneath the map is visible along the edges of the repeated stone texture. I tried the following:
    -Turning off AA
    -Enabling "Edge Filtering" on all terrain textures
    -Increasing "Border Size" on the environment texture page from 2 to 3
    -Disabling "Allow Scaling" on the texture page
    -Cleaning the project
    Sometimes it does this on sand tiles, and other times it doesn't.
     
  2. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,786
    Have you looked at the compiled texture page to make sure there are actually borders around each tile?

    You haven't accidentally got a bit of transparency in your drawings, have you?

    Also, are you totally sure you don't have gaps in your geometry?

    Looking at your picture closely, it seems to me the likely culprit is slight transparency in your images.
     
  3. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    165
    The images are 100% opaque, I just checked and made sure. I did look at the compiled texture page, and it did have the borders as expected. The geometry gaps wouldn't explain how it only appears on stone specifically.

    Maybe the geometry is slightly off, as that would explain the sub-pixel incorrect rendering. I will check to ensure that it is correctly calculating the edges.

    [​IMG]

    EDIT: The blue lines are not visible on any tile except the fully connected stone tile graphic.

    EDIT 2: I managed to fix it by increasing the Texture Page's Border Size to 4.

    EDIT 3: Increasing Border Size fixed the stone tiles, but now sand tiles have the exact same issue. Further increasing the Border Size does not fix the sand tiles.

    EDIT 4: Turning off all AA with a Border Size of 4 fixed the issue mostly. Very rarely while walking, I can see the blue lines flash into existence for a single frame. I cannot keep my view at integer values, as it makes the game appear awful, but I will round it to a certain fraction of a pixel to see if that helps.

    EDIT 5: This has introduced a few artifacts with unrelated textures on the Entities Texture Page (namely: Stationary entities with shadows now can be seen to have very minor but very noticeable artifacts).
     
    Last edited: Nov 9, 2018
  4. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    165
    Bump, this is still an issue. The exact tile it happens to changes every time I add or remove graphics to/from the texture page that the terrain is on. I cannot consistently get rid of the lines for every tile...
     
    Last edited: Dec 4, 2018
  5. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,786
    Are you able to upload a copy of the sprite(s) that you are having this issue with? It might also be a good idea to show the code you are using to write your vertex buffer.
     
  6. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    165
    The exact sprite the issue occurs with changes every time I create a new sprite, resize an existing sprite, or delete an existing sprite (basically, anything warranting cleaning the project). It has nothing to do with the sprite specifically. It only appears when my view is at a specific recurring position (the exact value of my view position that this occurs at: anything ending in 0.25 or 0.75, such as 1776.25, 1762.75, etc. Note that I multiply every size, distance, and speed by a global constant so that the game's resolution is larger than 1:1, so floating-point coordinates aren't an issue graphically. The exact scaling is 8, so those positions in the raw coordinates are: 14210, 14102, etc. Notice, those are integer positions causing the graphical glitches, as in the game-world ignoring scaling, the coordinates end in 0.25 or 0.75.)

    The important vertex buffer code looks like this (note, t = the current tile type, part of an enum, and system.scale is a constant (=8 at the moment), TS is a macro corresponding to how large 1 tile is in raw coordinates (scale (8) * tile size (8) = 64):
    Code:
    var lx = 0, rx = 1;
    var tx = 0, bx = 1;
    var sub = autotile_get_ext_any(tile_data,cx,cy,false,tile.water);
    var sh = system.scale;
    var sh_a = 0.4;
    var uvs = -1;
    switch(t)
    {
        case tile.grass:
            uvs = sprite_get_uvs(spr_grass_shore,sub);
            break;
        case tile.sand:
            uvs = sprite_get_uvs(spr_sand_shore,sub);
            break;
        case tile.beachsand:
            uvs = sprite_get_uvs(spr_beachsand_shore,sub);
            break;
        case tile.dirt:
            uvs = sprite_get_uvs(spr_dirt_shore,sub);
            break;
        case tile.stone:
            uvs = sprite_get_uvs(spr_stone_shore,sub);
            break;
        case tile.snow:
            uvs = sprite_get_uvs(spr_snow_shore,sub);
            break;
        case tile.cobble:
            uvs = sprite_get_uvs(spr_cobblestone,0);
            break;
        case tile.lightsand:
            uvs = sprite_get_uvs(spr_lightsand_shore,sub);
            break;
        case tile.gravel:
            uvs = sprite_get_uvs(spr_gravel,0);
            break;
        case tile.forest:
            uvs = sprite_get_uvs(spr_forest_shore,sub);
            break;
                        
        case tile.wood:
            uvs = sprite_get_uvs(spr_tile_wood,sub);
            break;
                        
        default:
            uvs = sprite_get_uvs(spr_tex_missing,0);
            break;
    }
    if (is_array(uvs))
    {
        lx = uvs[0];
        tx = uvs[1];
        rx = uvs[2];
        bx = uvs[3];
    }
                
                
    vertex_square(vb,cx*TS,cy*TS+sh,TS,lx,tx,rx,bx,c_black,sh_a);
    vertex_square(vb,cx*TS,cy*TS,TS,lx,tx,rx,bx,c_white,1);
    
    vertex_square is a custom script I made to make the code easier to read. Here is that script:
    Code:
    /// @arg vbuff
    /// @arg x
    /// @arg y
    /// @arg size
    /// @arg lx
    /// @arg tx
    /// @arg rx
    /// @arg bx
    /// @arg color
    /// @arg alpha
    
    var vb = argument0, xx = argument1, yy = argument2, sz = argument3;
    var lx = argument4, tx = argument5, rx = argument6, bx = argument7;
    var col = argument8, a = argument9;
    
    //TL
    vertex_position(vb,xx,yy);
    vertex_texcoord(vb,lx,tx);
    vertex_color(vb,col,a);
                        
    //TR
    vertex_position(vb,xx+sz,yy);
    vertex_texcoord(vb,rx,tx);
    vertex_color(vb,col,a);
                        
    //BL
    vertex_position(vb,xx,yy+sz);
    vertex_texcoord(vb,lx,bx);
    vertex_color(vb,col,a);
                        
    //TR
    vertex_position(vb,xx+sz,yy);
    vertex_texcoord(vb,rx,tx);
    vertex_color(vb,col,a);
                        
    //BR
    vertex_position(vb,xx+sz,yy+sz);
    vertex_texcoord(vb,rx,bx);
    vertex_color(vb,col,a);
                        
    //BL
    vertex_position(vb,xx,yy+sz);
    vertex_texcoord(vb,lx,bx);
    vertex_color(vb,col,a);
    
     
  7. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,786
    That you say it affects different sprites depending on the build, makes me think it has to be a problem with the texture itself.

    Can you upload a copy of the texture, while including information about which sprites were affected during that build? Oh, and if you can manage it, also post whatever sprite_get_uvs returns for that sprite. If all that looks good, then we can pretty much rule out anything wrong with the texture.
     
    Last edited: Dec 4, 2018
  8. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    165
    By "the texture", do you mean the entire texture page? If so, I'm not quite sure how to export the texture page as a *.png.

    Note: It ONLY happens when the view is at specific x-coordinates. It is not constantly visible.
     
    Last edited: Dec 5, 2018
  9. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,786
    In GMS1, and I presume it can be done the same way in GMS2, if I go to global game settings, and then to the target platform tab, and then to the graphics tab, I can press a button to compile the game textures and open the folder containing them.
     
  10. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    165
    I found it. You have to go to Options -> Windows -> Graphics -> Click "Preview" next to "Texture Page Size".

    Here is the texture page the environment is on (The border size is set to 4, and cropping is disabled):
    [​IMG]
     
    Last edited: Dec 5, 2018
  11. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,786
    So, at the time that texture was built, which sprites were giving you issues? And what are their texture uvs?
     
  12. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    165
    At the time that texture was built, it was the dirt tile (the one that is a full 8x8 dirt tile, at position 253x373). I forgot to grab the uvs. I have added more graphics since then, so now the dirt tile is no longer showing those lines. I haven't checked every tile type to see if any of them are, but one of them probably is.
     
  13. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,786
    If you encounter the problem again, try to identify the sprite, upload the compiled texture for that build, and get the uvs with something like:
    Code:
    var _uvs = sprite_get_uvs(sprite,sub_image);
    var _str =
        string_format(_uvs[0],0,14) + ", " +
        string_format(_uvs[1],0,14) + ", " +
        string_format(_uvs[2],0,14) + ", " +
        string_format(_uvs[3],0,14) + ", " +
        string_format(_uvs[4],0,14) + ", " +
        string_format(_uvs[5],0,14) + ", " +
        string_format(_uvs[6],0,14) + ", " +
        string_format(_uvs[7],0,14);
    clipboard_set_text(_str);
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice