I’m going to try to make a nice easy introduction to my two favorite functions in Houdini VEX (besides `fit01 `

and `chramp `

of course): `xyzdist`

and `primuv`

. These functions are at the core of a lot of really useful and cool tricks in Houdini, including rivets, the attributeInterpolate SOP, the old “droplets falling down a soda can” effect, and some really awesome stuff with volume shaders. I’ll do a little example of each as a way of showing off what you can do with these clever little tools.

First, let’s take a look at the VEX definition (the third overload here is the most frequently used):

`float xyzdist(string geometry, vector pt, int &prim, vector &uv, float maxdist)`

At its most basic, `xyzdist`

will return the distance from the sample point `pt`

to the nearest point on the surface `geometry`

. Note that this doesn’t mean the nearest actual *point*, but the interpolated surface in between those points.

Those little “&” symbols mean that this function will *write* to those parameters, rather than just read from them. So if we feed this function an integer and a vector, in addition to the distance to the surface, it will also give us the primitive number `prim`

and the parametric UVs on that primitive `uv`

. Note that parametric UVs are *not* the same as regular UVs… this just means the normalized position relative to the individual primitive we found.

So, what can we do with this? Click below to find out… (more…)