Professional Documents
Culture Documents
Vex Theory
Vex Theory
1 VEX THEORY
This is not a lesson, but rather a collection of ideas and concepts that will help a user who is
becoming familiar with VEX/SHOPs and how it all fits into Houdini.
Path Structure
$HFS/houdini
VEX
SOP
POP
CHOP
COP
VEXsop
VEXpop
VEXchop
VEXcop
Root
directories
containing
.vex .vfl
and .ds
files
or
$JOB/houdini/
Same as above.
$HOUDINI_PATH only set when you want vex files in other than the
following directories:
Windows NT .; ./houdini ; $HOME/houdini ; $HFS/houdini/
IRIX .: ./houdini : $HOME/houdini : $HFS/houdini/
Houdini Training
VEX THEORY
Start root
$HOME/houdini/vex
include $HFS/houdini/vex/VEX*op
$JOB/houdini/vex
include $HOME/houdini/vex/VEX*op
etc...
Option2
$HFS/houdini/vex
root
$JOB/houdini/vex
include $HFS/houdini/vex/VEX*op
Option 3
$JOB/houdini/vex
root
/usr/local/houdini
include $JOB/houdini/vex/VEX*op
Houdini Training
VEX THEORY
In Summary
You can control what Houdini sees. It is possible to have job control over vex operations.
This will also allow you to limit the number of OPs in the UI. If you had several hundred custom OPs, then it would be a nightmare.
If somebody talks about VEX, they are more than likely talking about writing a custom shader
for Houdinis Mantra4 renderer. VEX is much broader than just a shader writing tool. VEX can
be broken up into two different distinct groups. VEX OPs, and SHOPs.
VEX OPs
SHOPs
1.3 VCC
Not only does the VCC command act as a compiler, but if you when you are in the shell, and
type vcc -X <opname> then you get a help menu that lists all of the context information about
that particular VEX operator.
For help information on VCC type vcc -h then you will get the general helplist printed to the
screen.
Houdini Training
VEX THEORY
surface
Lambert(
vector amb=1;
vector diff={0.545, 0.525, 0.306};
)
{
vector nml;
nml = frontface(normalize(N),I);
Cf = amb * ambient()+diffuse(nml);
Cf*=diff;
}
Houdini Training
VEX THEORY
Displacement bounds - When VMantra is rendering a scene, it calculates the spacial bounds for
each primitive in the scene. When you use a displacement shader on a primitive, the value of the
displacment may cause areas of the object to protrude outside of the pre-calculated spatial bound.
This will result in ugly black triangles appearing on the rendered geometry. To fix this, you must
adjust the Displace Bound parameter in the objects Render folder. This value must be slightly
larger than the value of you displacment.
It is also important to note that you can use a combination of a displacement SOP, which displaces the points on a surface, and use the displacment values (map or random values) with a displacment shader. This creates a hybrid vex operator.
Antialiasing - When a continuous signal is sampled at equally spaced sample points, it is possible to take the sampled data, and reconstruct the signal through interpolation.
If the frequency of the signal changes, and the rate of the sampling remains, then the reconstructed signal can be dramatically different.
To compensate for this, you must sample the data at twice the highest frequency of the data. This
is called the Nyquist frequency.
Houdini Training
VEX THEORY
You can see that even though the sample rate has been doubled, there are still errors in the reconstructed signal.
How do you know what the sample rate of your material is to avoid aliasing?
There are several different ways to deal with the problem. Some of which are reletovely simple,
but may result in much longer render time. Others can be much more complex techinically speaking.
Brute Force - This method is easy, you simply increase the shading quality of the object. This
will more than likely fix any antialiasing problem that you have, but the trade off is that every
time you increase the shading quality, you rendering times will increase dramatically.
Texture maps - You can use a texture map instead of relying on the renderer to generate the
image. This does has its downsides which stem from the fact that you are using a texture map.
Filter clamping - This is bassed on taking an estimation of the highest frequency, and clamping
the frequency to increase the accurac of the sample.
1.7 NOISE
Procedural noise can be used to help create a variety of natural phenomenon. Noise can be
used to add slight bumping or displacements to surfaces that seem regular. It can be used to add
noise to to edges, stripes, bricks or any other transition between different colours or regions.
dSince there are several different types of noise, here is a breakdown of the different value
ranges.
noise (value)
- returns a value from 0 to 1.
- generates a rough looking noise.
- general noise used most of the time.
onoise (value)
- returns values form -1 to 1.
- for purists, this is exact perlin noise function.
snoise
- returns values from -1.7 to 1.7.
- generates a bubbly looking noise.
anoise
- returns values from -1 to 1.
Noise can be used to vary the color of a surface for example. In the following lines of code, an
offset value is included as wellas a frequencey value to control the shape of the noise.
surface
randcolor(
Houdini Training
VEX THEORY
vector diff = 1;
float offset = 0;
float freq = 1;
float amp
= 1;
)
{
float turb;
vector PP;
This generates a simple variation in the saturation of the colour. You can try substituting noise with snoise(PP), onoise (PP) and anoise(PP). Remember the value that the noise
generates, you may have to add abs in front of the noise. High frequency noise values can
cause buzzing in the noise.
The rest attribute - The rest attribute is generated in houdini using the rest SOP, and will
Lock down your points to the geometry. If your geometry deforms, the noise will stick. You
have to declare rest as a vector in the parameters in order to pick this up from the geometry.
surface
paintedtex(
vector diff = 1;
float intensity = 1;
string map = ;
Houdini Training
VEX THEORY
vector uv=0
)
{
float
ss, tt;
vector
dclr;
vector4 mapclr;
dclr = diff;
if (map != )
{
if (isbound(uv)) //test to see if uvs are bound to surface
{
ss = uv.x;
tt = uv.y;
}
else
{
ss = s;
tt = t;
}
if (ss >= 0 && ss < 1 && tt >= 0 && tt < 1)
{
// Look up the color (with alpha)
mapclr = texture(map, ss, tt); //picks up alpha too
dclr *= (1 - mapclr.a); //Scale the original color by alpha
dclr += mapclr;
dclr *= intensity;
}
}
Cf = dclr;
Of = Cf;
Af = mapclr.a;
}
Houdini Training
VEX THEORY
This shader picks up both RGB and Alpha by setting mapclr to be a vector4 variable. This
shader also incorperates if() statements to make the shader more efficient in time and memory
consumption.
isbound - The use of the isbound function is used to test if the uvs are present on the surface,
and if they are, use them to set ss and tt.
The function is mapclr = texture(map, ss, tt);
This returns the correct colour pre-filtered to reduce sparkles. It is best to use .rat image files,
as they reduce the likelihood of sparkles, and are extremely memory efficient due to the fact
that the image has embedded multiple resolutions.
surface
metallic(
vector BROWN = { 0.1307, 0.0609, 0.0355 },
BLUE0 = { 0.4274, 0.5880, 0.9347 },
BLUE1 = { 0.1221, 0.3794, 0.9347 },
BLUE2 = { 0.1090, 0.3386, 0.8342 },
BLUE3 = { 0.0643, 0.2571, 0.6743 },
BLUE4 = { 0.0513, 0.2053, 0.5377 },
BLUE5 = { 0.0326, 0.1591, 0.4322 },
BLACK = { 0, 0, 0 };
vector spec = 1,
opac = 1;
float amb = 1;
)
{
vector Nf = normalize(frontface(N, I));
vector V = normalize(-I);
vector R;
Houdini Training
VEX THEORY
vector Rn;
vector Ct;
float altitude;
Notice that the first and last colours in the cspline() function are repeated to get the correct
shape in the cardinal spline curve.
lspline() - Similar to the cspline() function there is the lspline() function which generates a linear spline between the points evenly along the curve. This function does not require the doubling up of the first and last points.
ckspline() - A third function is the ckspline() function which can place the points at arbitrary
positions along the curve form 0 to 1.
ckspline (t; val1, key1, val2, key2, ...valn, keyn)
This function requires two values to place a knot or point in the curve: The value to place (val),
and where along the curve to place the value (key).
10
Houdini Training
VEX THEORY
basic information in
- geometry
- lights both ambient and normal
- atmospheric objects
- bound shaders
Displacement
Shader
Light
Shader
Light Shadow
Shader
- dimport()
Surface Shader
-dimport()
-limport()
Fog Shader
- dimport()
- limport()
- simport()
This diagram shows how message passing occurrs in the render pipeline, and what information
can be extracted. For example, a surface can extract an exported parameter from a displacement shader, but a displacement shader cannot pick up anything from any of the bound shaders.
You have to decalare an export function in the parameters of a function:
displace
foodisplace(export float turb = 1);
{
...
}
Houdini Training
11
VEX THEORY
Now in the surface shader, you can pick up this variable by picking this in the body of the
shader.
surface
foosurface (diff = 1)
{
float surfturb;
dimport (turb, surfturb);
...
}
12
Houdini Training