View Full Version : gl_depth_clamp_nv sample code ?

12-02-2003, 03:23 AM

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

12-02-2003, 06:39 AM
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! http://www.opengl.org/discussion_boards/ubb/smile.gif


12-02-2003, 12:19 PM
hi cass,

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

first here a normal view (http://mapage.noos.fr/equentric/normal.jpg) of a scene with a few objects.

here's the near clipping without depth_clamp (http://mapage.noos.fr/equentric/disable_near.jpg)

here's the near clipping with depth_clamp (http://mapage.noos.fr/equentric/enable_near.jpg)
everything is fine !!

here's the far clipping without depth_clamp (http://mapage.noos.fr/equentric/disable_far.jpg)

here's the far clipping wit depth_clamp (http://mapage.noos.fr/equentric/enable_far.jpg)
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 ??!!

12-02-2003, 12:46 PM
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).]

12-03-2003, 12:35 AM
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.