Depthmask using texture instead of mesh

Good day,

Sorry for the long post, I’m trying to be as clear as possible.

I’m not an experienced shader programmer and I’m trying to accomplish something that I think could be solved using shaders. If you have other ideas on how I could solve my issue you’re welcome!

To simplify what I’m trying to accomplish let’s say that I’m working with a Kinect. The Kinect sends 60 times per seconds:

  • An RGB image
  • A Depth image of the user
  • The skeleton information of the user

Let’s say that I’m using the skeleton information in Unity to place an animated 3D mesh that has transparency and turns around the user head.

The rendering is basically the RGB image blended with the rendered mesh.

The problem I’m facing is that I’d like to hide what would be normally rendered behind the user head.

Unless I’m wrong (I don’t have a lot of experience with shaders) it’s the kind of problem that would be solved by using shader right?

For instance, this example in the wiki:

The difference between that example and what I’m trying to accomplish is that it uses a mesh and I’d like to use the Depth image to determine what should be rendered or not.

So basically my question is do you think what I’m trying to accomplish is possible using shaders? If it’s possible do you know an example or keywords that will guide me to this result? Otherwise how would you manage a such occlusion?

I’ve been thinking of generating a mesh using the depth map to occlude the rotating 3D Mesh, or using particles. However it would be 640*480 vertices/particles to update every frames.

If I understand you correctly, here is a discussion about writing to z-buffer with a fragment shader:
http://forum.unity3d.com/threads/66153-Writing-depth-value-in-fragment-program