Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: procedural generation offset calculation and movement

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2017

    procedural generation offset calculation and movement

    EDIT: I solved it now, but Noob as I am - I cannot figure out how to delete this post :/

    I am currently messing around a bit with procedural generation.

    Unfortunatly I have two problems ( details below):
    First, after moving 11 chunks in the same direction, the offset between chunks does not work anymore.
    Second, the overall offset for a 64*64 Chunk is only correct if set to 60. If I set it to 64, there is a gap of (suprise) 4 Tiles.

    I am quite sure, that has to do with my matrices, but I cannot figure out, what is going wrong.

    I render 9 Chunks at a time to get a 3*3 square rendered.
    The center Chunk is the one the player is in, as I move the world and not the player, the player can never exit the center chunk.

    Each Chunk is rendered by an instanced draw call to a tile with the top left coordinates of the chunk - I will call that one the ChunkTile.
    Furthermore Each Chunk is 64*64 Tiles with each Tile being scaled to 16*16 by its model matrix.

    When generated, the chunks are stored with their world coordinates as key in an unordered map.

    For each direction I have a transition vector (northwest, north, northeast etc)

    After crossing the border of a chunk into one direction, I redraw the scene by assigning my DrawStorage the correct chunks, e.g.:
    move to west
    DrawStorage before


    DrawStorage after:


    The new center is assigned first, and then the new Chunks are either generated or loaded from storage.
    Their world coordinates are always found by center-worldcoordinates + transitionVector

    The transition vector is basically the offset between the chunks.
    To stay with the example transitionwest = (-60,0)

    To get the right Position on Screen I keep track of the player World and Screenposition.
    Each new Chunk gets its world Position:

    and Screen Position:

    The Screenposition is used to get the translation-part in the modelmatrix done.

    Apparently after moving 11 chunks west (or any other direction), the offset between chunks is growing and even more weirdly, if I move several times west/east over the same border, the offset grows even further.

    I know it has probably something to do with the way I process my movement, but right now I cannot see anything wrong with it.
    My movement is basically 8 Screenunits(Pixels) and 0.5 Worldunits.

    My whole matrix-stuff works (at least for the first 10 chunks) in the way that I set the offset for the instanced drawing to 1.0f, meaning 1 World Unit is 16px on the screen.
    However I draw 64 Tiles per Chunk but the offset between each Chunk is 60 and I did not figured out how that can actually be.

    In the shader it is like: glPos = MVP*vec4(VertexVector+Offsetvector , 1.0f)
    The offset is stored in the instanced buffer and is basically the TL Worldposition +1 on x/y for each tile.
    So for the top left of the north Chunk at initialising the world it is:
    glPos = MVP*[(-0.5f, 0.5f, 0.0f)+(0.0f,-60.0f,0.0f)
    The next one right would havfe a Offset.x = 1 instead and so on.

    The translation to the correct Screenposition happens in the MVP.

    It is all with an ortho matrix. The window, ortho and viewport are set to 1024/768.

    Any suggestion why this could happen? I know we won't solve this directly here, but right now I cannot see where the miscalculation actually happens.
    Thanks anyway!
    Last edited by Labidusa; 12-14-2017 at 03:31 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts