Friday, June 10, 2011

Houdini Notebook #3: Camera Clipping Points/Particles

Here is a neat trick that will clip points or particles that are not seen through the camera. Note that this will not work well with geometry.

After your particles, use a UV Texture SOP and set it to 'Perspective From Camera'. Enter the camera you are using. This will create a uv[3] point attribute onto the particles. In the field of view of the camera, u is the horizontal, v is the vertical, and w is the depth. u and v range from 0 to 1, while w is the distance from the camera.

So after that, just use the Delete SOP and use $MAPU, $MAPV, and $MAPW to delete the range of uv values.

If you use 'Near Clipping' and 'Far Clipping' on the camera, the u, v, and w values of points that lay outside of the clip will be 0.

So before you copy objects on the particles, or add a particle fluid surface, you can use this trick to clip out the points you don't see in frame. This could avoid tons of unneeded calculations. But be careful if you have shadows or reflections, this might result in some popping.

You could also pad the deletion to be safe, say:
$MAPU <= -0.5 || $MAPU >= 1.5

Or maybe instead of just deleting the points, you could reduce detail or something.

Here is a Digital Asset that does all of this:
Download [ sop_cameraclip.otl ]