Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: 1D Perlin Noise

  1. #1
    Junior Member Regular Contributor
    Join Date
    Nov 2007
    Location
    London UK
    Posts
    242

    1D Perlin Noise

    Can someone point me in the direction of a 1D Perlin Noise shader function?

    I have 2D and 3D variations, but have't been able to find a 1D version.

    Cheers,

    a|x
    http://machinesdontcare.wordpress.com

  2. #2
    Junior Member Regular Contributor
    Join Date
    Nov 2007
    Location
    London UK
    Posts
    242

    Re: 1D Perlin Noise

    OK, answered my own question

    Code :
    uniform sampler2D PermTexture;			// Permutation texture
    const float permTexUnit = 1.0/256.0;		// Perm texture texel-size
    const float permTexUnitHalf = 0.5/256.0;	// Half perm texture texel-size
     
    float fade(in float t) {
    	return t*t*t*(t*(t*6.0-15.0)+10.0);
    }
     
    float pnoise1D(in float p)
    {
    	// Integer part, scaled and offset for texture lookup
    	float pi = permTexUnit*floor(p) + permTexUnitHalf;
    	// Fractional part for interpolation
    	float pf = fract(p);
    	//
    	float grad00 = texture2D(PermTexture, vec2(pi, 0.0)).r * 4.0 - 1.0;
    	float n00 = dot(grad00, pf);
    	//
    	float grad10 = texture2D(PermTexture, pi + vec2(permTexUnit, 0.0)).r * 4.0 - 1.0;
    	float n10 = dot(grad10, pf - 1.0);
    	// Blend contributions
    	float n = mix(n00, n10, fade(pf));
     
    	return n;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •