# Heightmap of points vertex(or geometry) shader

I’m playing with geometry shaders and try to generate a heightmap. In CPU side I have generated a grid of points like this :

``````const int NUM_X = 140;
const int NUM_Z = 40;`

const float HALF_SIZE_X = 100.0f/2.0f;
const float HALF_SIZE_Z = 100.0f/2.0f;

GLfloat* data = (GLfloat*)malloc( (NUM_X*NUM_Z * 3) * sizeof(GLfloat));

int count = 0;
int i, j;
for( j=0;j&lt;NUM_Z;j++) {
for( i=0;i&lt;NUM_X;i++) {
data[count] = ((((float)(i))/(NUM_X-1)) *2-1)* HALF_SIZE_X;
data[count+1] = 0.0f;
data[count+2] =((((float)(j))/(NUM_Z-1))*2-1)*HALF_SIZE_Z;
count+=3;
}
}
``````

and in GPU side I transform this points in cubes in the geometry shader.

What I want to do is to generate a heightmap from this grid of points in the vertex or geometry shader like a minecraft. I know i have to use an algorithm like perlin noise or simplex noise but I have no idea how to implement them to obtain a terrain. I saw some code found in webgl-noise but it’s not conclusive and I don’t understand it very well. I tried to convert the array in a texture but it’s the same thing.

I want to generate heightmap in the shader because when we move it will generate a new heightmap with the same points. It will give the impression we will move but it’s just the terrain on y axis changes. But my problem is I don’t know how to generate this terrain.

Any idea how to do, please ?

Minecraft doesn’t use heightmaps.

It was an example of what kind of terrain I want. Sorry for the mistake.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.