PDA

View Full Version : z fighting with arb_vertex_program



wizzo
04-20-2004, 11:15 AM
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\
#\n\
# This is a sample ARB Vertex Program\n\
#\n\
ATTRIB iPos = vertex.position;\
ATTRIB iColor = vertex.color;\
# We need 2 texture units to perform the PPL\n\
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\n\
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\n\
MOV oColor, iColor;\
# Temp Vector from the Light to the Vertex\n\
SUB tmp, vertex.position,lightpos;\
# Scale the light\n\
MUL oTex0, tmp, Radiusfactor;\
# Write out the 1 texture coordinates directly\n\
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

Jan
04-20-2004, 12:42 PM
OPTION ARB_position_invariant;

Put that at the beginning of your vertex-program.

Jan.

wizzo
04-21-2004, 03:35 AM
I tried to put the OPTION like this

"!!ARBvp1.0\n\
OPTION ARB_position_invariant;\n\
#\n\
# This is a sample ARB Vertex Program\n\...

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 (http://www.ece.fr/~miffre/public/tmp2.jpg)
www.ece.fr/~miffre/public/tmp3.jpg (http://www.ece.fr/~miffre/public/tmp3.jpg)

Cab
04-21-2004, 03:57 AM
Originally posted by wizzo:
I tried to put the OPTION like this

"!!ARBvp1.0\n\
OPTION ARB_position_invariant;\n\
#\n\
# This is a sample ARB Vertex Program\n\...
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

Nutty
04-21-2004, 04:02 AM
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

mikeman
04-21-2004, 04:32 AM
Originally posted by wizzo:
I tried to put the OPTION like this

"!!ARBvp1.0\n\
OPTION ARB_position_invariant;\n\
#\n\
# This is a sample ARB Vertex Program\n\...

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 (http://www.ece.fr/~miffre/public/tmp2.jpg)
www.ece.fr/~miffre/public/tmp3.jpg (http://www.ece.fr/~miffre/public/tmp3.jpg) 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.

wizzo
04-21-2004, 05:16 AM
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

mikeman
04-21-2004, 08:05 AM
glBlendFunc(GL_ONE,GL_ZERO) gives output:
C = 1*src+0*dst = 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.

wizzo
04-21-2004, 10:51 PM
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