My generated terrain chunks have gaps between them:

Gaps between terrain chunks

I'm using Compute Shader and Simplex Noise from FastNoiseLite library to generate noise:

 #pragma kernel GenerateNoise
#include "Includes\FastNoiseLite.compute"

RWStructuredBuffer<float> _Weights;

static const uint numThreads = 8;

int _chunkSize;
int _seed;

float _NoiseScale;
float _Amplitude;
float _Frequency;
int _Octaves;
float _GroundPercent;

float chunkPosX;
float chunkPosY;

int coordToIndex(int x, int y, int z)
    return x + _chunkSize * (y + _chunkSize * z);

[numthreads(numThreads, numThreads, numThreads)]
void GenerateNoise (uint3 id : SV_DispatchThreadID)
    fnl_state noise = fnlCreateState(_seed);
    noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
    noise.fractal_type = FNL_FRACTAL_RIDGED;
    noise.frequency = _Frequency;
    noise.octaves = _Octaves;

    float3 pos = id * _NoiseScale;
    float ground = -pos.y + (_GroundPercent * _chunkSize);
    float n = ground + fnlGetNoise3D(noise, id.x + (chunkPosX * _chunkSize), id.y, id.z + (chunkPosY * _chunkSize)) * _Amplitude;
    _Weights[coordToIndex(id.x, id.y, id.z)] = n;

Chunks have size of 16. I tried to increase my chunks size by 1, but this is impossible because numThread = 8 and as a result when I dispatched shader I have threads per group equal to 2 so my noise values for "extended parts" of chunks don't calculated.

Any ideas how to fix these "gaps"?

  • 1
    \$\begingroup\$ If you count the "cubes" in each direction, there are only 15. Either your first or last row and column is failing to render. \$\endgroup\$
    – Basic
    Commented Sep 5, 2023 at 21:58
  • 3
    \$\begingroup\$ Or you're generating 16 x 16 vertices per mesh (enough for 15 x 15 quads), but spacing your meshes as though they had 17 vertices / 16 quads in each direction. Changing your chunk spacing to account for the fact that only "interior" quads are generated might be all you need. \$\endgroup\$
    – DMGregory
    Commented Sep 5, 2023 at 22:18
  • 2
    \$\begingroup\$ Also note hat the last row/column of vertices for one chunk is the first row/column of the next. \$\endgroup\$
    – Philipp
    Commented Sep 6, 2023 at 7:20

1 Answer 1


I fixed this problem.

There were 16x16 vertices per mesh and new chunk coordinates were calculated as:

Vector2 chunkCoord = new Vector2((currentLocalChunkCoordX + x), (currentLocalChunkCoordY + y));

Now, I assume that there are 17x17 vertices per mesh, and the updated new chunk coordinates would be:

Vector2 chunkCoord = new Vector2((currentLocalChunkCoordX + x) * 0.9f, (currentLocalChunkCoordY + y) * 0.9f);

Now the problem is fixed:

enter image description here

Thanks for your responses.


You must log in to answer this question.

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