fragDepth (Composition by gtoledo3)

Author: gtoledo3
License: Public Domain
Date: 2012.10.20
Compatibility: 10.5, 10.6, 10.7, 10.8
Required plugins:

I was reading an OpenGL forum last night, and it became obvious that many people think you can't mix the results of a scene created with a fragment shader with objects created with vertices (like a Sphere or Cube, in QC world).

This composition shows how to write to gl_FragDepth, so that your scene can depth test against other geometry rendered in the scene. Specifically, it uses a Kinect input, in the most basic way possible, to make it very obvious how to tweak to your liking. Note that my hand is in front of the teapot in the sample image, while the rest of me is behind it. This is depth testing with the most basic kinect output image.

The same principle can be applied to stuff that's done programmatically in the fragment shader by taking whatever value represents the depth of the objects, and writing that to gl_FragDepth, usually with some number massaging.

(Thanks to cwright for showing me gl_FragDepth some years back.)