3D noise vertex problem

duran can

Member
Hi everyone, im trying to create 3d map with noise.
Like this video
i think someting wrong 😅
1.png
GML:
gpu_set_ztestenable(true);
gpu_set_zwriteenable(true);


w=600;
h=600;
size=4;

vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_normal();
vertex_format_add_texcoord();
vertex_format_add_color();
vertex_format = vertex_format_end();

vbuffer = vertex_create_buffer();
vertex_begin(vbuffer, vertex_format);

var iof=0;
for (var i = 0; i < w; i += size) {
    var jof=0;
for (var j = 0; j < h; j += size) {
    
    jof+=0.1;z[i,j]=noise(iof,jof,1);
}
iof+=0.1;
}
    

for (var i = 0; i < w; i += size) {
    for (var j = 0; j < h-size; j += size) {
        if ((i % (size*2) == 0 && j % (size*2) == 0) || (i % (size*2) > 0 && j % (size*2) > 0)) {
            var color = c_blue;
        } else {
            var color = c_white;
        }
    
        vertex_add_point(vbuffer, i, j, z[i,j],                0, 0, 1,        0, 0,       color, 1);
        vertex_add_point(vbuffer, i + size, j, z[i,j],           0, 0, 1,        0, 0,       color, 1);
        vertex_add_point(vbuffer, i + size, j + size, z[i,j],      0, 0, 1,        0, 0,       color, 1);

        vertex_add_point(vbuffer, i + size, j + size, z[i,j+size],      0, 0, 1,        0, 0,       color, 1);
        vertex_add_point(vbuffer, i, j + size, z[i,j+size],           0, 0, 1,        0, 0,       color, 1);
        vertex_add_point(vbuffer, i, j, z[i,j+size],                0, 0, 1,        0, 0,       color, 1);
    }
}

vertex_end(vbuffer);
 

sp202

Member
I think you're better off doing that in a vertex shader. Currently your triangles are disconnected from each other, in the shader you can use in_Position as an input to the noise function such that each vertex at a given position is at the same height.
 

duran can

Member
I think you're better off doing that in a vertex shader. Currently your triangles are disconnected from each other, in the shader you can use in_Position as an input to the noise function such that each vertex at a given position is at the same height.
i dont have any idea about shaders.
 

sp202

Member
That's fine, was just a suggestion that'll improve performance if you want to start animating. The real issue is that you're using the same noise array index for all 3 vertices of a triangle, you need to offset the index when you offset the position.
 
Top