Problem with vertex program.

A while ago I was trying to use some vertex program in my program, it did not really work out though. Just now I made another attempt and although the result was not better at all I think that I can describe my problem in a better way now.
(I am quite sure that the vertex program code is correct so I wont post it for now)

I am doing a multi-pass rendering to get per pixel lighting on a GF2, it is based on ron fraziers code, so if you know that one it might help.
The vp only alters the color to green (as a test)
-Enable vp.
-Draw the first pass (only geometry and
texture) for the ambient stuff.
-Disable vp.
-Draw diffuse light passes.

I get a green ambient color but the rest of the passes are somehow corrupted. I find it hard to describe, it looks just wrong.
Than I did this:
-Enable vp.
-Draw the first pass (only geometry and
texture) for the ambient stuff.
-Draw diffuse light passes.
-Disable vp.

This of course made all the light go away as I only proces color and 1 texture-unit, but the ambient was green and nice.

This makes me think that there is some problem with the multipass rendering.
Do I have to think about more than just to disable the vp after the first pass?
I know this is a long post and thank you for your time!

When the vertex program is transforming, the output vertex is not the same as it would be if you used fixed function T&L. You need to enable the “position invariant” option that’s in NV_vertex_program1_1, and ARB_vertex_program.

That’s right. If depth test is enabled, you have to use the position_invariant option, otherwise the fragment processed with and without vertex program enabled may have different depth values for the same mesh.

Ah, interesting, thanks for the hint!
I’m gonna try that, thanks.

How is this done?

[This message has been edited by B_old (edited 03-11-2003).]

The vertex program string should begin with :

OPTION ARB_position_invariant;

but then remember you don’t have to write the result.position output (ie discard the matrix multiplication by mvp).

Ah, thanks!
Now things start to look like something, giving me hope that I can pull off my idea anyway. Thanks!

I actually had to get rid of the ‘position’
in order to make it work…

you have to get rid of the output result.position, but you can use the input vertex.position

OK, thanks.
But can you have a look at this please:

cVector3 TexCoord = TSLight / (brightness * 2.0f) + 0.5f;
cVector3 SecondaryColor = TSLight * 0.5f + 0.5f;

glMultiTexCoord2fvARB(GL_TEXTURE0_ARB, (float*)&TexCoord);

If I use the following vp with the above code, should it not display correctly?

OPTION ARB_position_invariant;

ATTRIB In_ColorP = vertex.color.primary;
ATTRIB In_ColorS = vertex.color.secondary;
ATTRIB In_TexCoord0 = vertex.texcoord[0];

OUTPUT Out_ColorP = result.color.primary;
OUTPUT Out_ColorS = result.color.secondary;
OUTPUT Out_TexCoord0 = result.texcoord[0];

MOV Out_ColorP, In_ColorP;
MOV Out_ColorS, In_ColorS;
MOV Out_TexCoord0, In_TexCoord0;


Strangly enough I get a black screen. Do you have some idea what could cause this?
Thanks for the great help so far!

If texturing is enabled, color sum is enabled, lighting is disabled and fogging disabled, I think it should work.

If I were you I would disable texturing, disable color sum, disable lighting, disable fogging and replace the color operation with :
MOV Out_ColorP, 1;
which should give a white shape.

[This message has been edited by vincoof (edited 03-11-2003).]

OK, texturing is enabled, fogging and lighting is not. I never touched any color sum, is it on by deffault?

If I dissable the vp I get correct results and the vp I posted was designed in order to do nothing but to correctly display what is already there anyway. A test so to speak. Is there anything wrong with it? (Ah, I think you think that it is not wrong…)

I am willing to test it, but why would I want a white shape? (no sarcasm, plain question)

Thanks for the help!

I tried it again with a NV vp and came so far as to have an vp that actually displayed correct results although it wasn’t actually processing anything:

OPTION NV_position_invariant;

MOV o[COL0], v[3];
MOV o[COL1], v[4];
MOV o[TEX0], v[8];


If you remember the OGL-code i posted above, how would a vp look like that actually is doing is? Here is my attempt that delivers a black screen:

cVector3 Temp (1 / (Light->brightness * 2.0f), 0, 0);
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 4, Temp.X, 0.5, 0.0f, 0.0f );

//this one send with every vertex
glMultiTexCoord2fvARB(GL_TEXTURE1_ARB, (float*)&TSLight);

//and finnaly the vp
OPTION NV_position_invariant;

MAD o[COL0], v[TEX1], c[4].x, c[4].y;
MAD o[COL1], v[TEX1], c[4].y, c[4].y;
MAD o[TEX0], v[TEX1], c[4].x, c[4].y;


Can you see what is wrong?

[This message has been edited by B_old (edited 03-12-2003).]

color sum is disabled by default.

I’m sorry but I don’t really know NV_vp and can’t say much that could deliver theblack screen.

I suggest the white shape so that you will see there is a shape. If the shape is black and your background is black, you won’t notice much about anything drawn !

You couls also try rendering in wireframe. It helps recognizing shapes when colouring is messed up.

Well, OK then.
Thanks for the help!