PDA

View Full Version : weird behaviour of function argument



thinks
01-12-2005, 11: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

gulgi
01-12-2005, 01:53 PM
Originally posted by thinks:

vec3 glattice(vec3 vec)

.....

// 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));
You are casting a vec3 to a float (function param should be a vec3).
Have you checked what error-string you get..? It's kindof handy... ;]

thinks
01-12-2005, 02:33 PM
Thanks for the advice! What was in my code was obviously an error, it was the consequence of extensive debugging and frustration! =) I have changed it and it still doesn't work...

Any calls to glattice seem to break when function arguments are used.

The error code is:
"program object linking error, vertex info
fatal error C9999: ***exception during compilation***"

I have also been thinking about whether there is a type mis-match somewhere in the code. This would be a likely source of error, but I am not sure if the compiler should report this?

/ T

jra101
01-12-2005, 04:13 PM
Would you be able to post your entire shader along with the compile/link errors you are getting?

thinks
01-14-2005, 04:04 AM
Problem has been solved. The error was not from any function calls. It was from indexing arrays declared in the fragment shader proceduraly. The solution is to send the arrays as uniform values instead. Thanks for your time!

/ T