gl_depth_clamp_nv sample code ?


could someone tell me where to find any sample code or explanation about gl_depth_clamp_nv extension from nvidia.

I don’t manage to use it .
I think it would fill my zbuffer with 0 or 1 before or behind the clip planes. But my Zbuffer still have empty pixels as without gl_depth_clamp_nv extension.
funny ?!

thanks a lot

Be careful to use a glDepthFunc of GL_LEQUAL if you want stuff beyond the far clip plane to render. Otherwise, if you use GL_LESS and clear to 1.0 and clamped stuff has a depth of 1.0, stuff that gets clamped to 1.0 will fail the depth test.

Subtle, but important!


hi cass,

I can not send you any demo, but here are the screenshots that explains my problem.

first here a normal view of a scene with a few objects.

here’s the near clipping without depth_clamp

here’s the near clipping with depth_clamp
everything is fine !!

here’s the far clipping without depth_clamp

here’s the far clipping wit depth_clamp
there’s a problem : the background is not clipped (which is right) but the objects are clipped (which is wrong)

what do you think about it ??!!

just imagine, ( guess you draw background first?) after you drawed the background, your z buffer has a value of 1.0 there where usually the far clip plane would be. now the stuff you draw afterwards gets also clamped to 1.0 --> if your depth func is GL_LESS, z test will fail, so either draw background last or change the depth func to GL_LEQUAL, as cass suggested already.

[This message has been edited by ScottManDeath (edited 12-02-2003).]

hi guys,
thank you for your help.

I’ve checked the depthfunc call and it’s set to GL_LEQUAL as wanted.
And also, my background is drawn in last position.
But anyway that’s not so important, cause when I remove the background, the depthclamp behave as expected.
Don’t know why ?!! … but nevermind !

Another question :
Do you know how to clip the zbuffer to a dynamic far clipplane.
I’d like the zbuffer to be clipped to the farthest object in the scene if possible.

Is there any solution to do that, expect than using Bounding boxes of all the objects in the scene ??!!

thank you again.