Shading issue on generated vertex terrain


I’m currently working on a small OpenGL (JOGL) project where I generate a terrain using simplex noise.
To create some depth in the terrain while moving the camera, I want to add shaders over the texture.
What I tried so far:
Using a 1D texture to assign different colors to different heights.
Using a second material over the 1D texture to try and give it shading.

The results are as follows:
-I cannot insert images in this post, see first reply for screenshots
As you can see, ‘stripes’ appear in the landscape when using the material.

What I have is the following:
-The code that draws the field:

    public void draw(GL2 gl, GLU glu, GLUT glut, Drawer drawer) {
        if (showGrid)
            gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_LINE );
        ArrayList<Vector[]> normals = new ArrayList<>();
        for(int i=1;i<vectors.length;i++) {
            for (int j = 0; j < vectors[i].length; j++) {
                Vector normalTopRight, normalBottomLeft;

                //Calculate normals top right
                Vector v1, v2, triangleCenterTR;
                if (j < vectors[i].length - 1)
                    v1 = vectors[i-1][j].subtract(vectors[i][j]);
                    v2 = vectors[i][j+1].subtract(vectors[i][j]);
                    normalTopRight = v2.cross(v1).normalized();
                    // Get center (a+b+c)*(1/3)
                    triangleCenterTR = (vectors[i][j].add(vectors[i - 1][j]).add(vectors[i][j + 1])).scale(1.0 / 3);
                } else {
                    v1 = vectors[i-1][j].subtract(vectors[i][j]);
                    v2 = vectors[i][j-1].subtract(vectors[i][j]);
                    normalTopRight = v1.cross(v2).normalized();
                    // Get center (a+b+c)*(1/3)
                    triangleCenterTR = (vectors[i][j].add(vectors[i-1][j]).add(vectors[i][j-1])).scale(1.0/3);
                normals.add(new Vector[] {triangleCenterTR, triangleCenterTR.add(normalTopRight)});

                if (j != 0)
                    v1 = vectors[i][j].subtract(vectors[i-1][j]);
                    v2 = vectors[i-1][j-1].subtract(vectors[i-1][j]);
                    normalBottomLeft = v2.cross(v1).normalized();
                    // Get center (a+b+c)*(1/3)
                    Vector triangleCenterBL = (vectors[i - 1][j].add(vectors[i][j]).add(vectors[i - 1][j - 1])).scale(1.0 / 3);
                    normals.add(new Vector[]{triangleCenterBL, triangleCenterBL.add(normalBottomLeft)});
                } else {
                    normalBottomLeft = null; // If j==0, there is no bottom left triangle above

                 * We have everything to start drawing
                // Shift left
                // Set some color
                if (j == 0) {
                    // Initialization vector
                } else {

                gl.glTexCoord1d(mapTextureToHeight(vectors[i - 1][j].z));
                drawer.glVertexV(vectors[i - 1][j]);

                // Right down diagonally
                if (j < vectors[i].length - 1) { // Skip if we are reached the end
                    gl.glTexCoord1d(mapTextureToHeight(vectors[i][j + 1].z));
                    drawer.glVertexV(vectors[i][j + 1]);
        if (showGrid)
            gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_FILL );
        if (drawNormals) {
            for (Vector[] arrow : normals) {
                if (yellowNormals)
                drawer.drawArrow(arrow[0], arrow[1], 0.05);


mapTextureToHeight returns a double (0.0 -> 1.0) based on the height,
whereas the ‘texture’ variable is a 1D texture where 0.1 = water color, 0.25 = sand color, etc.

Does anyone have any idea what might be causing those stripes?
My idea is the sudden change in the normal vector per vertex, causing the light to cast different on certain triangles. Is there any way to ‘smoothen’ this?
Let me know if you need to see more code/classes

any help will be greatly appreciated!


The results are as follows:

With the material disabled:

With the material enabled:

The normals are calculated correctly as you can see here:

Sorry, I’m appearently not allowed to insert pictures or even url links into posts…

This is my material use method:

public void use(GL2 gl) {
        // set the material properties
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_AMBIENT, ambient, 0);
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE, diffuse, 0);
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SPECULAR, specular, 0);
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SHININESS, shininess, 0);

Terrain material:

     * TERRAIN material properties.
            new float[]{0.5f, 0.5f, 0.5f, 1.0f},
            new float[]{0.7f, 0.7f, 0.7f, 1.0f},
            new float[]{0.2f, 0.2f, 0.2f, 1.0f},
            new float[]{100f});

Here is one more screenshot of the problem: