You can create a custom compositing operation with VOPs or raw VEX. Custom COPs created with VEX are very similar to other generators and filters, with a few extra features:
All VEX-based generators have the same characteristics as normal generators .
Generators do not have inputs. You set the image size, data format, frame range and planes in the node.
VEX-based filters inherit sequence settings (image size, data format, frame range, planes) from their first input.
All VEX-based filters have a mask input to control the effect of the filter per-pixel.
VEX-based compositing operators cannot:
Change any of the sequence parameters: the length or start of the sequence, the resolution or the data format of existing planes.
Write to multiple output pixel locations at a time.
Do more than one pass over the data (multi-pass algorithms).
Efficiently use globally computed data (like the average luminance of the image). The node runs the VEX script for each pixel, so the global data would need to be recalculated for each pixel.
A VEX/VOP COP must write to one of the following variable sets:
Amap directly to the Color plane’s
C4map to the currently processed plane’s components.
All of these variables can be read as well as written. For generators, they will contain black. For filters, they will contain the value of the corresponding image plane in input #1.
X,Y return the position of the current pixel in 0-1 notation. IX,IY return the position of the current pixel in 0 to XRES-1, 0 to YRES-1.
Often you need to process different planes differently (like Color and Alpha). You can do this by testing the
PNAMEvariable (current plane name) against the planes you need to process (colorname, alphaname, etc.).
To read other pixel locations, image planes, frames, or other inputs:
The COP Input VOP allows you to pick the input, plane, frame and pixel location of the pixel you want to read. You can also specify how it is filtered - no filtering (fast), bilinear (for sub-pixel accuracy) and full filtered (slow, but good for continuous transforms or deformations)
The cinput, binput, and finput functions correspond to the no-filtering, bilinear and full filtered input functions. VEX also has a ninput function, which returns a 3×3 kernel of the pixel and its neighbors in a matrix. This is done per-component, so for color, you would need to call this 3 times.
Create a custom COP from VOPs
Go inside the node to the VOP network.
Create a Global Variables VOP. You will probably need to use some of the variables in your definition.
If you want to affect Color/Alpha only, use the
R,G,B,Aoutputs. If you want to generally affect any plane or a specific plane, use
Cr,Cg,Cb,C4. You can read the corresponding input values from
Cr,Cg,Cb,C4(even though you can’t write to both at once, you can still read from any of them).
To create parameters, connect Parameter VOPs to those inputs you want to control.
Once you've set up the VOP network, return to the VOP COP2 Generator/Filter Definition node. Change the name of the definition to the human readable name for the new operator type, and the internal name of the operator definition. You can also reorder the parameters as they will appear in the new node’s parameter editor interface.
Create an instance of the new operator and test it.
Create a custom COP from VEX code
Create a new text file with the
.vflextension (for example, myFunction.vfl). We recommend the name of the file match the name of the VEX function inside.
When writing the VEX function, use the context name
Write the results of your function to
To compile the COP to an OTL (the easiest way to use the code in Houdini), use the following command line:
vcc -l myfunction.otl myfunction.vfl
Arguments to the function show up as parameters for the new node type. You can use #pragmas to set the type, name, range, menu items and disable behavior of the parameters.
Getting data from the COP inputs into VEX/VOPs
If the first input has a plane which matches a VEX parameter’s name, the node will use the input plane as the parameter’s value (effectively overriding the parameter). The node evaluates the overloaded parameter from the plane on a per-pixel basis.
For example, if the COP has the following planes:
...and it is fed into a VEX Fog COP, the fog density will be
determined at each pixel by the
fogdens plane, since the Fog
Density parameter’s channel name is
Creating new planes from exported VEX variables
If the VEX script for a custom COP exports a variable, Houdini creates a new plane with the same name as the VEX parameter. If that plane already exists in the input sequence, it is replaced by the VEX version. Each VEX type maps to a COP data type:
|VEX Type||COP Type|
|int||Single channel 32 bit integer|
|float||Single channel 32 bit float|
|vector||3 channel 32 bit float|
|vector4||4 channel 32 bit float|
|matrix3||3 element array of 3 channel 32 bit floats|
|matrix4||4 element array of 4 channel 32 bit floats|
New planes are created as 32 bit floating point (except for int planes, which are 32 bit int) and their vector size is determined by the type of variable exported (float, vector, vector4).