<p>Based on the shader and the way it is using the noise texture there is to much &quot;white noise&quot; / &quot;cell noise&quot; in the noise texture.</p>
<p>Noise is usually built in layers with low frequencies making up the large features and higher frequencies making up the small features. The different frequencies are literally added together. Looking at the noise texture it looks like the high frequency &quot;bumps&quot; are either multiplied into the noise, or they are just overwritten directly. This will give very sharp edges and give the spiky result you are seeing.</p>
<p>Basically anywhere you see a sudden change from black to white in the noise you will get a cliff/spike.</p>
<p>To get the hilly looking terrain like the image you want then the noise texture should look something like this one:
<a href="https://i.sstatic.net/YFnEN.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YFnEN.jpg" alt="Gradual hills" /></a></p>
<p>The slow transition from black to gray then white gives the hills. This &quot;noise&quot; could also be described as low frequency, high amplitude noise.</p>
<p>To get the bumps this image would have the regular &quot;square&quot; pattern added in. This could be done in the shader itself by computing the pattern on a regular grid. That should make it easier to experiment with different amplitudes and frequencies for the pattern.</p>

CC BY-SA 4.0
2023-06-06T17:20:44.927Z
I wouldn't say the white noise is being caused in the image, I would say that the noise generator that created the image was generating a lot of white noise.  An old trick to smooth out noise is to just blur the texture in an image editor. Noise is one of those subjects that seems simple on the surface, but is actually fairly complex.
pmw1234
CC BY-SA 4.0
2023-06-06T00:26:59.213Z
2023-06-06T00:26:59.213Z
pmw1234
<p>I'm making a space game and so far what I have is a system to generate spheres with noise on them, making them planets. I make a sphere, create noise data, write that data to an image file, and then bind it to the sphere as a texture, and from there, I use that to make terrain. The problem I'm having is there are too many hills and valleys, and just looks like a spikeball instead of a planet
<a href="https://i.sstatic.net/HMGdf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HMGdf.png" alt="sphere" /></a></p>
<p><a href="https://i.sstatic.net/UNM3V.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UNM3V.png" alt="sphere wireframe" /></a></p>
<p>Here's the function I use to generate the noise data</p>
<pre><code>void write_noise_2d(int w, int h, int channels_num, const char* bmp_path)
{
        // create random seed for noise
        srand(time(NULL));
        float seed = (float)rand()/RAND_MAX;
        // initialize noise
        fnl_state noise = fnlCreateState();
        noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
        noise.octaves = 6;
        noise.lacunarity = 2.0f;
        noise.gain = 0.5f;
        noise.frequency = 0.01f;
        noise.seed = (int)seed;
        printf(&quot;Seed: %i\n&quot;, seed);
        noise.fractal_type = FNL_FRACTAL_FBM;
        // create data array for noise
        float* noise_data = malloc(w * h * channels_num * sizeof(float));
        int index = 0;
        // create noise throughout the entire image
        for(int x=0; x&lt;w; x++)
        {
            for(int y=0; y&lt;h; y++)
            {
                noise_data[index++] = fnlGetNoise2D(&amp;noise, x * 0.3f, y * 0.3f);
            }
        }

        stbi_write_bmp(bmp_path, w, h, channels_num, noise_data);
        free(noise_data);
}
</code></pre>
<p>Here's the function where I bind the noise to the sphere</p>
<pre><code>unsigned int load_noise_2d(const char* path, unsigned int shader_program, const char* sampler, 
bool remove_noise)
{
    unsigned int noise;
    glGenTextures(1, &amp;noise);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, noise);
    // from what I heard no need to specify gl_repeat because that is the default
    // filtering parameters
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_MIPMAP);

    // image stats
    int width, height, num_channels;
    // load image
    unsigned char* noise_data = stbi_load(path, &amp;width, &amp;height, &amp;num_channels, 0);
    if(noise_data)
    {
        // image options
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_SHORT, noise_data);
        glGenerateMipmap(GL_TEXTURE_2D);

        // send to the GPU for processing
        set_int(shader_program, sampler, 0);
        printf(&quot;Loaded noise map of %i by %i\n&quot;, width, height);
    }
    else
    {
        printf(&quot;Failed to load noisemap\n&quot;);
    }
    // deallocate data that's no longer needed
    stbi_image_free(noise_data);
    if(remove_noise == true)
    {
        remove(path);
        printf(&quot;Deleted noise file\n&quot;);
    }
    else
    {
        printf(&quot;Kept noise file\n&quot;);
        return 0;
    }

    return noise;
}
</code></pre>
<p>For reference, this is how the function calls look like</p>
<pre><code>    // write noise data from FNL to texture
write_noise_2d(512, 512, 2, &quot;textures/2dnoise.bmp&quot;);
// now we load the noise map back into the program to be used later
load_noise_2d(&quot;textures/2dnoise.bmp&quot;, earthlike, &quot;noisemap&quot;, true);
</code></pre>
<p>And finally, here's the tessellation shader, where I had a problem before with the intensity being too high, but that's solved</p>
<pre><code>#version 450 core

// determines what type of tessellation to do
layout(triangles, equal_spacing, cw) in;

// input from control shader
in vec3 vertex_coord[];
// output vec
out vec3 vert;
// simplex noise goes here
uniform sampler2D noisemap;
// allows for object transformations
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

out float height;

void main()
{
    // gets barycentric coordinates from the triangles
    vec3 x = gl_TessCoord.x * vertex_coord[0];
    vec3 y = gl_TessCoord.y * vertex_coord[1];
    vec3 z = gl_TessCoord.z * vertex_coord[2];
    vec3 v = x + y + z;
    // scale noise between an acceptable value
    float min_noise_value = 0.5f;
    float max_noise_value = 2.5f;
    float intensity_scale = 0.015f;
    float noise_range = max_noise_value - min_noise_value;
    // use texture for offsetting sphere vertices
    float noise = texture(noisemap, vec2(v)).r;
    // sphere offsetting multiplier
    height = min_noise_value + noise_range * noise * intensity_scale;
    // makes every triangle an equal distance from the center through normalization (that's how spheres are formed)
    vec3 pos = normalize(x + y + z);
    // apply noise
    pos *= height;
    // output tessellated shape
    gl_Position = projection * view * model * vec4(pos, 1.0);
}
</code></pre>
<p>For reference, this is sort of how I want my planet to look like instead
<a href="https://i.sstatic.net/AHYC4.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AHYC4.jpg" alt="notice how there is not a lot of frequency. It's just some occasional hills and valleys" /></a></p>

CC BY-SA 4.0
2023-06-05T19:04:23.277Z
The spiky look is usually the result of a lot of white noise in the noise texture. What does the noise texture look like?
pmw1234
CC BY-SA 4.0
2023-06-05T20:12:35.727Z
@pmw1234 https://i.imgur.com/LqOSbH7.png
Chillzy
<opengl><shader><glsl><noise>
How to scale down noise frequency?
Chillzy
# How to scale down noise frequency?

(Asked by: username_0 on 2023-06-05)

I'm making a space game and so far what I have is a system to generate spheres with noise on them, making them planets. I make a sphere, create noise data, write that data to an image file, and then bind it to the sphere as a texture, and from there, I use that to make terrain. The problem I'm having is there are too many hills and valleys, and just looks like a spikeball instead of a planet
[![sphere](https://i.sstatic.net/HMGdf.png)](https://i.sstatic.net/HMGdf.png)

[![sphere wireframe](https://i.sstatic.net/UNM3V.png)](https://i.sstatic.net/UNM3V.png)

Here's the function I use to generate the noise data

```
void write_noise_2d(int w, int h, int channels_num, const char* bmp_path)
{
        // create random seed for noise
        srand(time(NULL));
        float seed = (float)rand()/RAND_MAX;
        // initialize noise
        fnl_state noise = fnlCreateState();
        noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
        noise.octaves = 6;
        noise.lacunarity = 2.0f;
        noise.gain = 0.5f;
        noise.frequency = 0.01f;
        noise.seed = (int)seed;
        printf("Seed: %i\n", seed);
        noise.fractal_type = FNL_FRACTAL_FBM;
        // create data array for noise
        float* noise_data = malloc(w * h * channels_num * sizeof(float));
        int index = 0;
        // create noise throughout the entire image
        for(int x=0; x<w; x++)
        {
            for(int y=0; y<h; y++)
            {
                noise_data[index++] = fnlGetNoise2D(&noise, x * 0.3f, y * 0.3f);
            }
        }

        stbi_write_bmp(bmp_path, w, h, channels_num, noise_data);
        free(noise_data);
}

```

Here's the function where I bind the noise to the sphere

```
unsigned int load_noise_2d(const char* path, unsigned int shader_program, const char* sampler, 
bool remove_noise)
{
    unsigned int noise;
    glGenTextures(1, &noise);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, noise);
    // from what I heard no need to specify gl_repeat because that is the default
    // filtering parameters
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_MIPMAP);

    // image stats
    int width, height, num_channels;
    // load image
    unsigned char* noise_data = stbi_load(path, &width, &height, &num_channels, 0);
    if(noise_data)
    {
        // image options
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_SHORT, noise_data);
        glGenerateMipmap(GL_TEXTURE_2D);

        // send to the GPU for processing
        set_int(shader_program, sampler, 0);
        printf("Loaded noise map of %i by %i\n", width, height);
    }
    else
    {
        printf("Failed to load noisemap\n");
    }
    // deallocate data that's no longer needed
    stbi_image_free(noise_data);
    if(remove_noise == true)
    {
        remove(path);
        printf("Deleted noise file\n");
    }
    else
    {
        printf("Kept noise file\n");
        return 0;
    }

    return noise;
}

```

For reference, this is how the function calls look like

```
    // write noise data from FNL to texture
write_noise_2d(512, 512, 2, "textures/2dnoise.bmp");
// now we load the noise map back into the program to be used later
load_noise_2d("textures/2dnoise.bmp", earthlike, "noisemap", true);

```

And finally, here's the tessellation shader, where I had a problem before with the intensity being too high, but that's solved

```
#version 450 core

// determines what type of tessellation to do
layout(triangles, equal_spacing, cw) in;

// input from control shader
in vec3 vertex_coord[];
// output vec
out vec3 vert;
// simplex noise goes here
uniform sampler2D noisemap;
// allows for object transformations
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

out float height;

void main()
{
    // gets barycentric coordinates from the triangles
    vec3 x = gl_TessCoord.x * vertex_coord[0];
    vec3 y = gl_TessCoord.y * vertex_coord[1];
    vec3 z = gl_TessCoord.z * vertex_coord[2];
    vec3 v = x + y + z;
    // scale noise between an acceptable value
    float min_noise_value = 0.5f;
    float max_noise_value = 2.5f;
    float intensity_scale = 0.015f;
    float noise_range = max_noise_value - min_noise_value;
    // use texture for offsetting sphere vertices
    float noise = texture(noisemap, vec2(v)).r;
    // sphere offsetting multiplier
    height = min_noise_value + noise_range * noise * intensity_scale;
    // makes every triangle an equal distance from the center through normalization (that's how spheres are formed)
    vec3 pos = normalize(x + y + z);
    // apply noise
    pos *= height;
    // output tessellated shape
    gl_Position = projection * view * model * vec4(pos, 1.0);
}

```

For reference, this is sort of how I want my planet to look like instead
[![notice how there is not a lot of frequency. It's just some occasional hills and valleys](https://i.sstatic.net/AHYC4.jpg)](https://i.sstatic.net/AHYC4.jpg)

**Tags:** opengl, shader, glsl, noise

> **Comments:**
> **username_1**: The spiky look is usually the result of a lot of white noise in the noise texture. What does the noise texture look like?  
> **username_0**: @username_1 https://i.imgur.com/LqOSbH7.png  

---

## 1 answers

### Answer by username_1 on 2023-06-06. Score: 0 | Accepted answer

Based on the shader and the way it is using the noise texture there is to much "white noise" / "cell noise" in the noise texture.

Noise is usually built in layers with low frequencies making up the large features and higher frequencies making up the small features. The different frequencies are literally added together. Looking at the noise texture it looks like the high frequency "bumps" are either multiplied into the noise, or they are just overwritten directly. This will give very sharp edges and give the spiky result you are seeing.

Basically anywhere you see a sudden change from black to white in the noise you will get a cliff/spike.

To get the hilly looking terrain like the image you want then the noise texture should look something like this one:
[![Gradual hills](https://i.sstatic.net/YFnEN.jpg)](https://i.sstatic.net/YFnEN.jpg)

The slow transition from black to gray then white gives the hills. This "noise" could also be described as low frequency, high amplitude noise.

To get the bumps this image would have the regular "square" pattern added in. This could be done in the shader itself by computing the pattern on a regular grid. That should make it easier to experiment with different amplitudes and frequencies for the pattern.

> **Comments:**
> **username_1**: I wouldn't say the white noise is being caused in the image, I would say that the noise generator that created the image was generating a lot of white noise.  An old trick to smooth out noise is to just blur the texture in an image editor. Noise is one of those subjects that seems simple on the surface, but is actually fairly complex.  

---

