z fighting with arb_vertex_program

hi ! i tried to set up vertex_program lighting for the first time, and as i am very much a beginner in vertex program, i took slug production’s tutorial to start :

!!ARBvp1.0\

\

This is a sample ARB Vertex Program

\


ATTRIB iPos = vertex.position;
ATTRIB iColor = vertex.color;\

We need 2 texture units to perform the PPL


ATTRIB iTex0 = vertex.texcoord[0];
ATTRIB iTex1 = vertex.texcoord[1];
PARAM mvp[4] = { state.matrix.mvp };
PARAM lightpos = program.env[69];
PARAM Radiusfactor = program.env[70];
TEMP tmp;
OUTPUT oPos = result.position;
OUTPUT oColor = result.color;
OUTPUT oTex0 = result.texcoord[0];
OUTPUT oTex1 = result.texcoord[1];\

This just does out vertex transform by the modelview projection matrix


DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;\

Write our color out directly


MOV oColor, iColor;\

Temp Vector from the Light to the Vertex


SUB tmp, vertex.position,lightpos;\

Scale the light


MUL oTex0, tmp, Radiusfactor;\

Write out the 1 texture coordinates directly


MOV oTex1, iTex1;
END

the vertex program works fine : when i render only the lighting pass, it is correct; the same with only the base textured rendering… but when i render both, zfighting artifacts appear

i tried to put some polygon offset on the second pass, and part of the artifact disapeared, but some are still here…

i checked the old post and found the OPTION thingy, but it didnt work for me (the sphere on which i was applying my vp became transparent)

here is a shot of the problem : http://www.ece.fr/~miffre/public/tmp.jpg
if anyone can help, thanks in advance
wizzo

OPTION ARB_position_invariant;

Put that at the beginning of your vertex-program.

Jan.

I tried to put the OPTION like this

"!!ARBvp1.0

OPTION ARB_position_invariant;
\

\

This is a sample ARB Vertex Program

it did change something but this is no good : the sphere on which i applied the vp is now transparent and the “lit sphere” is lost somewhere…

www.ece.fr/~miffre/public/tmp2.jpg
www.ece.fr/~miffre/public/tmp3.jpg

Originally posted by wizzo:
[b]I tried to put the OPTION like this

"!!ARBvp1.0

OPTION ARB_position_invariant;
\

\

This is a sample ARB Vertex Program


[/b]
You not only have to put the option but also remove this lines:
OUTPUT oPos = result.position;
DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;\

Hope this helps

Do you use vertex programs for both passes? Or 1 with Vertex program, another fixed function?

The Position invariant option is used for invariance between mixing vertex program passes and fixed function passes.

When you add the position invariant option, did you remove the manual transform of the vertex position? Not sure if it compiles if you leave it in.

Did you remember to take the polygon offset out? What depth testing are you using on the 2nd pass? If its GL_LESS surely this will discard your 2nd pass where depth should be identical.

Thats all I can think of at the mo.

Nutty

Originally posted by wizzo:
[b]I tried to put the OPTION like this

"!!ARBvp1.0

OPTION ARB_position_invariant;
\

\

This is a sample ARB Vertex Program

it did change something but this is no good : the sphere on which i applied the vp is now transparent and the “lit sphere” is lost somewhere…

www.ece.fr/~miffre/public/tmp2.jpg
www.ece.fr/~miffre/public/tmp3.jpg [/b]
Even with differences in vertex positions,I don’t get why the sphere is transparent.Do you use blending in all the passes?You sould render the regular sphere with blending disabled,THEN enable blending and draw the lightmap with a second pass.

ok so the solution was to remove

OUTPUT oPos = result.position;
DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;\

thx cab for that =)

but i wanted to ask you something mikeman (and the others)

I read in different places that to blend to pass, the way of doing it was :
first pass : glBlendFunc(GL_ONE, GL_ZERO);
second pass : glBlendFunc(GL_DST_COLOR, GL_ZERO);

now that the vp is working properly, this ‘trick’ is also working… did any of you do differently and had good result… just wondering

thanks to you all for your help
wizzo

glBlendFunc(GL_ONE,GL_ZERO) gives output:
C = 1src+0dst = src
src is the incoming color and dst the color already present in the framebuffer.So,it’s exactly like when you have blending disabled.I don’t know which is faster,I guess disabling blending would work better,but don’t take my word for it,test it yourself.

you are totally mikeman, this is obvious (once you said it =))

Its cleaner that way, and probably faster with blending disable even if I couldn’t verify, because i dont render a large number of polygon (but i dont see how it could be otherwise)

thx for your help, mikeman

wizzo