ATI - GL_CLIP_DISTANCE0 - Bug

For reference to anyone else with the same problem:

The following works on NVIDIA but not on “ATI Radeon HD 4800 Series”

In the application:


	glDisable(GL_CLIP_DISTANCE0);
	glDisable(GL_CLIP_DISTANCE1);
	<-- Note Disable clip!

In the GLSL vertex shader:


	gl_ClipDistance[0] = -1000;"
	gl_ClipDistance[1] = -1000;"

The gl_ClipDistance is used, although disabled in the application via glDisable(GL_CLIP_DISTANCEi)

So how about when clipping is enabled in the CPU code?

In the code posted by rombust the gl_ClipDistance variables are set to some value that will effectively discard the primitive.

When GL_CLIP_DISTANCE0 or GL_CLIP_DISTANCE1 is enabled then both NVIDIA and AMD correctly renders nothing.

If you disable the clip distances using glDisable, the AMD driver still renders nothing while the NVIDIA driver renders the primitive.

Hmm, it is a rare case, but in my opinion, I think that GL state change at CPU side should have higher priority over shader code. I will talk to AMD shader team about this problem.

just my 2 cents…

I can imagine such a system where clip planes can be enabled and disabled by a user to look at different cut-aways of a model. The clipping planes might be displayed and moveable by an app and toggled on and off applied to a model.

The current ATI behavior leaves the planes always applied. From the specification:

I just programmed an example, which is setting gl_ClipDistance[0] in the vertex shader and disabling it with glDisable(GL_CLIP_DISTANCE0) in the main code. With the AMD Catalyst 12.1, the clip distance is still used. So I can confirm that this is a bug.

I love redundant state in GL. It’s just sooooo good.

I dislike redundant things too but the GL_CLIP_DISTANCE states are not one of them. They let you use the same shader with or without clipping.

Also all shader outputs have undefined values if they are used afterwards but the shader does not write them.
It wouldn’t be very elegant if clip distances are exception from this and writing/not writing in them implicitly enables/disables clipping.

Lets face it. GL stopped being elegant some time ago, and there is no coming back.

This would simplify stuff to ‘statically used - feature enabled’, and be user business to fill the variable appropriately.

Perf. impact would probably be negligible, as DX10 does it that way (if im not mistaken, don’t know DX10 all that well).

While i am not against the idea to be able to switch clipping on/off from within the shader alone, i’m certainly against doing it in this particular way.
Instead it could be some pragma or such.
Output variable that is not being written to should remain with undefined value.

Yeah. That would be good enough (its also what im saying, you would get undefined result when you statically use the variable but don’t actually write to it).

Also note, how GL actually works that way in some cases - gl_FragDepth kinda works like that.

You are right for gl_FragDepth it’s an exception from the undefined “rule”.
So it appears we already have exceptions anyway. Well, in that case… i cancel my objections :slight_smile:

In the mentioned example, I still write to the clip distance. But by disabling the clipping, I would expect - as written in the specs - that no clipping is done.

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