Drawing to JUST the depth buffer

Let’s say I am rendering a mirror surface on a flat convex surface. I use the edges of the surface to create clipping planes around the camera, move the camera in a position so that a reflection is rendered, then draw and move the camera back.

The only problem is that objects still get drawn behind the “mirror”. To make the “mirror” occlude objects that lie behind it, I rendered the surface with glBlendFunc set to GL_ZERO,GL_ZERO. This works pretty well, but I still get some graphical glitches, with objects behind the mirror flashing on and off as I move.

Is there a better way to make OpenGL think I drew an object on that surface, even though I just drew a clipped view from a different camera angle?

Here is an image of what I am doing. Here, I am actually using the same technique to render the skybox. There is a block of “sky” sitting on the road on the right. You can see the sky through it, and it blocks objects that are behind it. However, when I move around, there are some flashes of other objects on top of the sky surfaces.

I fixed it by rendering the sky first, followed by the surface, with a blend mode of zero, one.

Is there a better way to do this? I would prefer to do away with the big blended surfaces.

if you just want depthwrithing turn colormask to false
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE)
you will get a speed boost on most hardware I think, as they are faster on pure zpasses.

Hi!

I got the same problem as you with blending and skyboxes, things don’t get drawn well

…however I am kind of a newbie…

Could anyone explain me what does the

colormask to false
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE)

command do?

What does it mean to only write to the depth buffer, and how does it fix the initial problem?!

Thank you so much all in advance!
Cheers,
Rod

with glColorMask you say to which color channels you want to render. giving all false makes that nothing will be displayed, but it was rendered to depth buffer (if you don’t disable that too)

Nice soft shadows :wink: