gl_ClipVertex causes flickering

using clip planes in fixed functionality has never caused any trouble, but now that i’m using shaders all the time, i can’t get them working correctly. i set them up as usual and call gl_ClipVertex in my vs - geometry is clipped as expected, but moving/rotating the camera causes serious flickering. i’m using a gf7800gt. any ideas what’s wrong?

EDIT: i tried oblique depth projection desribed here: www.terathon.com/code/oblique.php as a work-around, but it totally messes up my geometry; i tried to do it in in software and in the vs. u_ProjectionMatrix is the input matrix:

	vec4 q;
	mat4 ProjectionMatrix = u_ProjectionMatrix;
	vec4 clipPlane = vec4( 0.0, -1.0, 0.0, 0.0 );

	q.x = (sign(clipPlane.x)+ProjectionMatrix[2][0])/ProjectionMatrix[0][0];
	q.y = (sign(clipPlane.y)+ProjectionMatrix[2][1])/ProjectionMatrix[1][1];
	q.z = -1.0;
	q.w = (1.0+ProjectionMatrix[2][2])/ProjectionMatrix[3][2];

	vec4 c = clipPlane * (2.0/dot(clipPlane, q));

	ProjectionMatrix[0][2] = c.x;
	ProjectionMatrix[1][2] = c.y;
	ProjectionMatrix[2][2] = c.z+1.0;
	ProjectionMatrix[3][2] = c.w;

I’ve run in to something similar in the past. As it turns out, clipping creates new vertices in post-projection space (IE: after the vertex shader and during triangle setup for rasterization). That implies that the clip plane state has to be the same between passes. In other words, you’ll get flickering from the following:

  • one pass uses user clip planes and another pass doesn’t

  • the values passed to gl_ClipVertex between passes are different.

The reason this causes flickering is because the rasterization of the primitives changes slightly. Hope that explains what you’re seeing! =)

Kevin B

al passes use the same planes.

Do they use the same shader? Perhaps driver optimization or slight differences in calculations are causing the values passed to gl_ClipVertex to be slightly different…

Kevin B

… i was wrong, problem still there.

btw - has anyone tried Lengyel’s suggestion yet?
Yup, works beautifully.

ok i finally found the bug - i have not been updating the fixed function modelview matrix… obviously it is still needed for clipping internally. thanks :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.