I have a particle effect that I only want to be render while inside of another mesh. The mesh is semi-transparent and is not back-face culled. By moving the particles to the Transparent+1 queue, I could get them to draw within the mesh, but they are still drawn when outside.

(See bubbles above, they shouldn’t be drawn when outside the character.)
Basically I want to do a culling mask, like here, but I want to, but I kind of need to write to an inverse z-buffer (only draw when occluded). Is such a thing possible?
This could also be accomplished if I passed the vertices of my person-mesh into my particle shader, but would obviously be pretty computationally expensive. Another option would be to somehow render the person-mesh and the particles with the same shader. Any ideas?
Solved it! So, it seems that when doing anything complicated with front and back faces (i.e. drawing between them), it is necessary to have two different materials. In the situation above if the Transparent man has a front material and a back material, the rendering can go like this (pseudo code):
Back Material:
Queue = Transparent
Pass {
Cull Front
<Draw the back side>
}
Pass {
Cull Back
ZWrite On
ColorMask 0 // This writes to the z-buffer, but doesn't actually draw anything
}
Particles:
Queue = Transparent + 1
Pass {
ZTest GEqual // Only draw particles if there's something between them and the camera
<Render particles as normal>
}
Front Material:
Queue = Transparent + 2
<Draw front side>
This way the renderer draws the backside, particles then the frontside, in that order, due to the different queues. The key is drawing a z-mask of the front side when you draw the backside, then using a GEqual Z-test on the particles so that they’re only drawn if something appears in front of them.