Include.cl Source Reference


Below is the source reference to the types and functions available to Luminoise modules, as well as member descriptions.

Item Description
Single3 A simple type created to make up for the lack of 3-dimensional vector types in the OpenCL 1.0 specification.
perm(__global int *p, int index) A function for retrieving the permutation value from buffer p at index , where index is wrapped around 512.
float noise(__global int *p, float x, float y, float z) The perlin noise function. It returns a single noise value at location < x , y , z >, using permutation buffer p


typedef struct
{
    float x;
    float y;
    float z;
} Single3;

float fade(float t) { return t * t * t * (t * (t * 6 - 15) + 10); }

float lerp(float t, float a, float b) { return a + t * (b - a); }

float grad(int hash, float x, float y, float z) {
   int h = hash & 15;
   float u = (h < 8) ? x : y;
   float v = (h < 4) ? y : ((h == 12 || h == 14) ? x : z);
   return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
}

float perm(__global int *p, int index)
{
    return p[index % 512];
}

float noise(__global int *p, float x, float y, float z)
{
    int X = (int)floor(x) & 255;
    int    Y = (int)floor(y) & 255;
    int    Z = (int)floor(z) & 255;

    x -= floor(x);
    y -= floor(y);
    z -= floor(z);

    float u = fade(x);
    float v = fade(y);
    float w = fade(z);

    int A = perm(p, X + 0) + Y, AA = perm(p, A) + Z, AB = perm(p, A+1) + Z,
        B = perm(p, X + 1) + Y, BA = perm(p, B) + Z, BB = perm(p, B+1) + Z;

    return lerp(w, lerp(v, lerp(u, grad(perm(p, AA  ), x  , y  , z   ),
                                    grad(perm(p, BA  ), x-1, y  , z   )),
                            lerp(u, grad(perm(p, AB  ), x  , y-1, z   ),
                                    grad(perm(p, BB  ), x-1, y-1, z   ))),
                    lerp(v, lerp(u, grad(perm(p, AA+1), x  , y  , z-1 ),
                                    grad(perm(p, BA+1), x-1, y  , z-1 )),
                            lerp(u, grad(perm(p, AB+1), x  , y-1, z-1 ),
                                    grad(perm(p, BB+1), x-1, y-1, z-1 ))));
}

Last edited Sep 13, 2010 at 4:11 PM by YellPika, version 10

Comments

No comments yet.