PDA

View Full Version : Vertex Program help!



chracatoa
06-03-2003, 02:34 PM
I am trying to do something very simple using vertex programs but some weird things are happening.

I have the following calls:
-----
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,1 ,U.x,U.y,U.z,1);
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,2 ,V.x,V.y,V.z,1);

(...) /* glBegin, etc. */

glVertexAttrib4fARB(20,ecenter.x,ecenter.y,0,1);
glVertex4f(...);
(...)
-----
and I just want to do a very simple calculation: the new vertex position will be equal to ecenter.x*U+ecenter.y*V. This is my code:
-----
!!ARBvp1.0
PARAM U = program.env[1];
PARAM V = program.env[2];
PARAM mvp[4] = { state.matrix.mvp };

ATTRIB pos = vertex.position;
ATTRIB color = vertex.color;
ATTRIB intexcoord = vertex.texcoord;
ATTRIB ecenter = vertex.attrib[20];

OUTPUT opos = result.position;
OUTPUT outcolor = result.color;
OUTPUT outtexcoord = result.texcoord;

TEMP tmp1,tmp2,npos;

# npos = ecenter.x * U + ecenter.y * V

MUL tmp1,ecenter.x,U;
MUL tmp2,ecenter.y,V;
ADD npos,tmp1,tmp2;

DP4 opos.x, mvp[0], npos;
DP4 opos.y, mvp[1], npos;
DP4 opos.z, mvp[2], npos;
DP4 opos.w, mvp[3], npos;

MOV outcolor, color;
MOV outtexcoord,intexcoord;

END
-----
I am still not using vertex.position, vertex.color.secondary and other parameters because I will use them as soon as I fix this simple problem. The final computation will be much more complex.

Any ideas?

[This message has been edited by chracatoa (edited 06-03-2003).]

Humus
06-03-2003, 04:01 PM
.. and what exactly is the problem?

chracatoa
06-03-2003, 04:24 PM
It just doesn't work... the result should be a checkboard pattern, but instead it's like a pencil of dotted lines coming from a point...

However, if I disable GL_VERTEX_PROGRAM and use this instead:

P3d newp = ecenter.x*U+ecenter.y*V;
glVertex3f(newp.x,newp.y,newp.z);

it works!

Korval
06-03-2003, 04:45 PM
ATTRIB ecenter = vertex.attrib[20];

This tells a lot. Now, granted, I'm not 100% familiar with ARB_vp syntax, but, if I understand correctly, you're asking for the 20th vertex attribute. Of course, there are only 16 per-vertex attributes avalible. I don't know how the program is compiling.

Now, let's assume that this isn't the problem, and I'm simply interpreting it incorrectly. It's still a generic attribute, that you're using along-side non-generic attributes (glVertex, glColor, etc). So, I've got to ask: are you send the attribute properly? Also, are you sending it in an index that might alias with a non-generic attribute? Which attribute index are you using to send your generic data?

chracatoa
06-04-2003, 08:31 AM
Originally posted by Korval:
Of course, there are only 16 per-vertex attributes avalible.

Just changed it to 10 and I still have the problem... The only attributes/parameters I am using now are those in the program and they don't alias.

Anyway, even if I don't use any generic attribute and send ecenter.x and ecenter.y as:

glVertex3f(ecenter.x,ecenter.y,0);

and change the vertex program:
MUL tmp1,pos.x,U;
MUL tmp2,pos.y,V;
ADD npos,tmp1,tmp2;

It still doesn't work. I could bet that the error is very simple, perhaps due to some misunderstanding of my part of how MUL works. But at this point I can't see it.

jwatte
06-04-2003, 09:16 AM
Are you calling glGetError() after loading the vertex program? Did it come back with no error?




assert( !glGetError() ); // sprinkle liberally all over your code

chracatoa
06-04-2003, 09:22 AM
Originally posted by jwatte:
Are you calling glGetError() after loading the vertex program? Did it come back with no error?

Yes, no errors after loading the program. If there is any compilation error my program halts.

chracatoa
06-04-2003, 09:31 AM
By the way, if I do this:
---------------
TEMP ex,ey;

MOV ex.x,ecenter.x;
MOV ex.y,ecenter.x;
MOV ex.z,ecenter.x;
MOV ex.w,1.0;

MOV ey.x,ecenter.y;
MOV ey.y,ecenter.y;
MOV ey.z,ecenter.y;
MOV ey.w,1.0;

# npos = ecenter.x * U + ecenter.y * V

MAD tmp1,ex,U,P;
MAD npos,ey,V,tmp1;
---------------
I can see the checkboard pattern, though it's size is wrong (too small) and its center is off.