thinks

01-12-2005, 10:01 AM

I am currently developing a very primitive form of gradient "noise" in a vertex shader. Tecknically it might be wrong to even call it noise, but it has a rather similar effect. I will post (relevant parts of) the code to simplify explaining:

#define TABSIZE 16

#define TABMASK TABSIZE - 1

// const?

int permtable[TABSIZE] = {

5, 9, 2, 7, 10, 8, 11, 3, 15, 6, 13, 12, 1, 4, 14, 0

};

// const?

vec3 vdir[TABSIZE] = {

vec3(-0.3429, 0.8639, -0.3689), vec3(0.3442, 0.1373, -0.9288),...

};

int perm(float x)

{

int i = int(abs(mod(x, float(TABMASK))));

return permtable[i];

}

int index(vec3 vec)

{

int tmp = perm(vec[2]);

tmp = tmp + int(vec[1]);

tmp = perm(tmp);

tmp = tmp + int(vec[0]);

tmp = perm(tmp);

return tmp;

}

vec3 glattice(vec3 vec)

{

int i = index(vec);

return vdir[i];

}

vec4 hnoise(float ax, float ay, float az, float at)

{

// Integer parts of input vector

vec3 invec = vec3(ax, ay, az);

vec3 ipart = abs(floor(invec));

// THIS CALL TO GLATTICE DOESN'T WORK!

// GIVES LINKER ERROR

vec3 tmp2 = glattice(float(ipart));

// THIS CALL TO GLATTICE DOES WORK!

vec3 tmp66 = glattice(vec3(0.0, 1.0, -2.0));

// result = [x,y,z,r], r = radius

// DOESN'T DO ANYTHING AT THE MOMENT

// SINCE THE OTHER STUFF DOESN'T WORK!

vec4 result;

result.x = 1.0;

result.y = 0.0;

result.z = 0.0;

result.w = at;

return result;

}It is all very confusing. The conclusion I have come to is that I can't really do anything with the input to hnoise... At the moment the function doesn't do much. It has been stripped to show the problem more clearly.

/Tommy

#define TABSIZE 16

#define TABMASK TABSIZE - 1

// const?

int permtable[TABSIZE] = {

5, 9, 2, 7, 10, 8, 11, 3, 15, 6, 13, 12, 1, 4, 14, 0

};

// const?

vec3 vdir[TABSIZE] = {

vec3(-0.3429, 0.8639, -0.3689), vec3(0.3442, 0.1373, -0.9288),...

};

int perm(float x)

{

int i = int(abs(mod(x, float(TABMASK))));

return permtable[i];

}

int index(vec3 vec)

{

int tmp = perm(vec[2]);

tmp = tmp + int(vec[1]);

tmp = perm(tmp);

tmp = tmp + int(vec[0]);

tmp = perm(tmp);

return tmp;

}

vec3 glattice(vec3 vec)

{

int i = index(vec);

return vdir[i];

}

vec4 hnoise(float ax, float ay, float az, float at)

{

// Integer parts of input vector

vec3 invec = vec3(ax, ay, az);

vec3 ipart = abs(floor(invec));

// THIS CALL TO GLATTICE DOESN'T WORK!

// GIVES LINKER ERROR

vec3 tmp2 = glattice(float(ipart));

// THIS CALL TO GLATTICE DOES WORK!

vec3 tmp66 = glattice(vec3(0.0, 1.0, -2.0));

// result = [x,y,z,r], r = radius

// DOESN'T DO ANYTHING AT THE MOMENT

// SINCE THE OTHER STUFF DOESN'T WORK!

vec4 result;

result.x = 1.0;

result.y = 0.0;

result.z = 0.0;

result.w = at;

return result;

}It is all very confusing. The conclusion I have come to is that I can't really do anything with the input to hnoise... At the moment the function doesn't do much. It has been stripped to show the problem more clearly.

/Tommy