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,
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,
OK, answered my own question
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;
}
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.