Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smoothing low octave perlin noise

I'm trying to create super simple Perlin noise clouds in a fragment shader, using the Noise function found here.

At low octaves my output is, for want of a better word, 'blobby'. I'd simply like to smooth out these blobby areas and have smooth noise but have it a little more detailed than just one octave.

Fragment shader:

#ifdef GL_ES
precision mediump float;
#endif

uniform float time;
uniform vec2 resolution;

// Noise related functions go here ..

float surface3 ( vec3 coord ) {
        float frequency = 4.0;
        float n = 0.0;  

        n += 1.0    * abs( cnoise( coord * frequency ) );
        n += 0.5    * abs( cnoise( coord * frequency * 2.0 ) );
        n += 0.25   * abs( cnoise( coord * frequency * 4.0 ) );

        return n;
}

void main( void ) {
        vec2 position = gl_FragCoord.xy / resolution.xy;

        float n = surface3(vec3(position, time * 0.1));

        gl_FragColor = vec4(n, n, n, 1.0);
}

Live example:
http://glsl.heroku.com/e#1413.0

Left is what I have at the moment. How would I be able to achieve something more inline with the right image?

like image 902
Robin Pyon Avatar asked Oct 09 '22 21:10

Robin Pyon


1 Answers

The easiest way is to take out two of the noise calls in the surface function. Leave just the first noise call line and you get something that looks like the first one:

http://glsl.heroku.com/e#1450.0

The sharp lines in the multi-octave noise come from using abs(), remove the abs() and replace it with squaring the noise value or doing something like 0.5*(1.0+cnoise()) (if cnoise output is between -1..1).

Here's the result of some fiddling http://glsl.heroku.com/e#1450.1

like image 128
Ilmari Heikkinen Avatar answered Oct 12 '22 00:10

Ilmari Heikkinen