VEX

About

← Back

User Interface

Add & Delete Presets

Input the VEX to be saved as a preset and navigate to the gear icon at top right corner of Properties panel and select Save Preset... This will prompt to save the preset with a name and to a specified location.

To delete presets, follow the same path as noted above and select Delete Preset... which will prompt to identify the preset to delete.

Once saved, the preset can be recalled from other wrangles in current project or other projects based on where the preset is saved to. For more information about saving locations, reference link below.

image

Custom presets are being saved to the specified location.

Source: https://www.sidefx.com/docs/houdini/ref/windows/savepreset.html

image

Channels

Channel Ramps

The following outlines the steps for generating ramp parameters within a Wrangle.

image
image

Access Attributes Via Operator Inputs

When using point(), prim(), and the like, @opinput provides an alternative way to access input stream attributes.

Math Operations

Round To Even Integer

Normalized Values Between -1 & 1 Range

In instances where normalized values need to be mapped, or fit, between -1 and 1 range, the following are some methods that can be utilized.

A case in which the above methods can be of value is using the returned values from a rand() operation, which are between 0 and 1, to specify a range of random values between -1 and 1, as shown in the video below.

Clamped Cycle

Define time-dependent cycle operation.

image

Clamp time-dependent cycle operation separated by user-defined clamp length.

image

Clamp time-dependent cycle operation to positive values and separated by user-defined clamp length.

image

Noise

Alligator Noise

Data Type Operations

Data Type Specification

When an attribute's data type is first specified in a Wrangle, such as the following string array: s[]@test,

subsequent references to @test will read the same without having to specify the data type again.

Source: https://www.sidefx.com/docs/houdini/vex/snippets.html#arrays

Data Type Conversions

Format String

Variable Values

set() or array() can be used to initialize dynamic variable values. Curly braces are used to initialize static values.

Array Operations

Detail Attributes

The following images display the corresponding return values for each Wrangle.

Wrangle 1

image

Wrangle 2

image

Wrangle 3

image

Point Operations

Point Iteration via Detail Wrangle

@curveu Attribute

While the Resample SOP can assign the @curveu attribute, this same operation can be applied through VEX.

Connect Near Points

Optimized Scatter Points

Optimized scatter points generation within defined bounds using VEX; alternative to IsoOffset & Scatter with Box SOP.

Map Point Attribute To Local Variable

Create and map a point attribute to a local variable in Houdini, as an alternative to using the Attribute Create SOP. This is particularly useful in linking template point attributes to copy instances via the Copy Stamp SOP.

Source: https://www.sidefx.com/docs/houdini/vex/functions/addvariablename.html

Primitive Operations

Pad Number In Fracture Name

Delete Primitives By Point Count

image

Carve Functionality In VEX

The groom library is located in the Houdini install location $HFS\houdini\vex\include\groom.h and includes the following function that can be configured to replicate the actions of the Carve SOP.

#include <groom.h>
adjustPrimLength(const int geo, prim; const float currentlength, targetlength)

Performance Comparison

Comparing the Carve SOP with a Prim Wrangle utilizing the above VEX snippet shows a significant difference in performance.

image

Group Operations

Group Naming Syntax

Flow Control Operations

Inline & Ternary If Statement

Variations in formatting simple inline if statements in Houdini Vex. Complex conditionals should utilize base formatting for clarity.

Source: https://www.sidefx.com/docs/houdini/vex/statement.html#if

Break Statement

Switch/Case Statement Alternative

Base Setup

The Base Setup above outputs the following for the 4 points in the Geo Spreadsheet. Note that Point 3 has an @test of 1, which ran through the 2nd condition, but then was overwritten by the 3rd condition.

However, the Switch/Case Alternative below used the prev_executed variable to serve as the 'break' to exit the Wrangle. As a result, Point 3 in the Geo Spreadsheet shows that it preserved the output (@test = 1 and @case = CASE 1) from the 2nd condition and did not run through the 3rd condition.

Base Setup

image

Switch/Case Alt Setup

image

Switch/Case Alt Setup

Functions

Each of the following sections is a periodic exploration of a different Vex function and its application in Houdini. My aim is to use this daily routine to familiarize myself with the wide range of available functions.

relbbox() & relpointbbox()

The bounding box of the incoming geometry is redefined into a range from 0-1 and returns a value within that range for each prim or point in the geometry. As a result, it can then be passed into something like a channel ramp that accepts a normalized (to 0-1 range) value. Both of these function within either a point or primitive wrangle using the positions of the respective geometry elements to define the relative positions.

In this example, the color is driven by the relative position in the y-axis ranging from 0 (bottom of geo) to 1 (top of geo). The returned @Cd values in the Geo Spreadsheet show the range from 0-1.

The last condition was a quick check to verify that the returned values in either the Primitive or Point Wrangle and use of relbbox() or relpointbbox() were equal.

image
image

Reference: https://www.sidefx.com/docs/houdini/vex/functions/relbbox.html

Reference: https://www.sidefx.com/docs/houdini/vex/functions/relpointbbox.html

volumevoxeldiameter()

This exploration of the function documents how voxel and VDB sizes are extracted with use of the volumevoxeldiameter() function to show its relationship with the bounds and number of voxels.

The above Primitive Wrangle outputs the following to Primitive 0 in the Geo Spreadsheet:

image

The returned values for the attributes assigned to Primitive 0 in the Geo Spreadsheet are confirmed by the node information to the right. In particular, the number of voxels on each axis align with the size of the @surface VDB and @voxel_len matches the Voxel Size

In the video below, the small green box is the individual voxel relative to the bounding box of the VDB. It is sized to the @voxel_len attribute calculated from the volumevoxeldiamter() and the VDB bounds.

image

Reference: https://www.sidefx.com/docs/houdini/vex/functions/volumevoxeldiameter.html

volumesample()

This first example is documentation of using the volumesample() Vex function to analyze voxel information from a VDB converted to a volume. Each voxel is then represented by a point with color attributes aligning with their corresponding volume sample values.

The output of the above Primitive Wrangle in the Geo Spreadsheet shows the volume resolution with use of volumeres().

The size of each voxel is transferred to each point's @pscale so that the Box passed into the Copy To Points are sized to represent the voxels.

The video below showcases the voxel's sample values extracted from the volumesample(). Voxel size and bands are adjusted to showcase visual impact of sample voxel values.

image

This next example is a variation of the above process that retains the original VDB as a VDB and then is processed through a similar script. Part of the variation is the removal of point representations based on the volume sample values.

The following is the corresponding output from the above Primitive Wrangle which attributes the volume resolution with volumeres() and volume origin with volumeindexorigin(), which specifically identifies the bottom left corner of the VDB's active bounds.

image

This video demonstrates the VDB's voxel size and bands being adjusted to showcase visual impact of sample voxel values. The original geometry's material is transferred to @Cd for each voxel representation.

Reference: https://www.sidefx.com/docs/houdini/vex/functions/volumesample.html

rotate()

The rotate() function applies a defined angle amount rotation around a specified axis. An identity matrix stores the rotation transformation and is then passed into the rotate() along with the angle (in radians) and the axis. In this example, a sequence of rotations are applied; first around the @up axis and then the @N axis. Each of the angle amounts are driven by channel parameters for user-control.

NOTE: Specify angles in radians and axes as normalized.

Operating the channel parameters drives the angles in the use of the rotate() function. Of particular note is the sequence of rotations as they are each applied. Rotating around the @N axis first followed by rotating around the @up axis aligns each to the updated axes. However, when the rotation is first applied around the @up axis, rotation around the @N axis is around the original state of the @N axis and not the updated @N axis following the rotation around the @up axis.

Using the rotate() function's variation with the xyz rotation order argument results in the same rotation operation and controls as in the vector-defined function above.

Reference: https://www.sidefx.com/docs/houdini/vex/functions/rotate.html

resize()

This function is applied to array data structures.

image

Reference: https://www.sidefx.com/docs/houdini/vex/functions/resize.html

detailintrinsic()

Detail intrinsics can be accessed in the detail section of the Geo Spreadsheet and coordinated with VEX for applications such as identifying the groups available in the geo stream and specific to each geometry element, such as points or primitives.

image
image
image

VEX Resources

Resources

General

Global Variables

Environment

Variables

Attribute$Description
File Directory

$HIP

Directory where current Houdini scene file is located.

Project Directory

$JOB

Directory where current Houdini project is located.

Scene File Name w/out Extension

$HIPNAME

Does not include file extension, $HIPFILE does.

Home Directory

$HOME

Directory where current Houdini version directory is located, in which .env file is located.

Source: https://www.sidefx.com/docs/houdini/ref/env.html

Indexing

Variables

AttributeType@$Description
Number of Points
Integer

@numpt

Total number of points in current geometry.

Point Number
Integer

@ptnum

Channel

Variables

AttributeType@$Description
Operator String
String

$OS

Refers to a node's title name.

Copy

Variables

AttributeType@$Description
Current # of Copy Instance
Integer

$CY

Total # of Copy Instances
Integer

$NCY

Source: https://www.sidefx.com/docs/houdini/nodes/sop/copy.html#locals

Playback

Variables

AttributeType@$Description
Fractional (Sub) Frames
Float

$FF

Applicable for precision, such as motion blur.

Frame
Integer

@Frame

$F

Current frame.

Frames Per Second
Float

$FPS

Set in the Global Animation Options.

Simulation Time
Float

@SimTime

ST

Current simulation time.

Simulation Timestep
Float

@SimFrame

$SF

Current simulation timestep number as applicable in dynamic simulations. $SF = $ST / $TIMESTEP

Simulation Timestep Size

$TIMESTEP

Time
Float

@Time

$T

Current time in seconds.

Time Step
Float

@TimeInc

Equals 1/$FPS

Math

Variables

AttributeType@$Description
e
Constant

$E

pi
Constant

$PI

Attributes

Geometry

Attributes

AttributeType@Description
Normal
Vector

@N

Normal vector of the element.

Color Diffuse
Vector

@Cd

Color diffuse using RGB values for the vector.

Position
Vector

@P

Position of element.

Points

Attributes

AttributeType@Description
Scale (Non-uniform)
Vector

@scale

Non-uniform scale with each float representing each axis: x, y, z.

Scale (Uniform)
Float

@pscale

Uniform scale of element.

Orient
Quaternion

@orient

Orientation of the element. This takes precedence over @N if both @N and @orient exist in element. But if @orient does not exist in element, then @N defines its orientation along Z-axis. Since @N is simply a vector and @orient is a quaternion, then @orient has greater precision, and therefore precedence.

Particles

Attributes

AttributeType@Description
Acceleration
Vector

@accel

Can be calculated via Trail SOP set to Compute Velocity and Compute Acceleration.

Id
Integer

@id

Unique value identifying an element, such as a particle. Even after it dies, another element or particle will not acquire that id value.

Age
Float

@age

Denotes the time that the particle has been in existence since spawning, or being born, from its origin. Value is in seconds and typ. noted as fractions per the frame rate.

Life
Float

@life

Number of seconds that the particles are expected to live. Defined in the POP Source.

Dead
Integer

@dead

An attribute to mark particles that have @age > @life.

Age / Life
Float

@nage

Unlike @age, which is just a recording of time that the particle has been alive, @nage is a percentage of how long it has been alive relative to its @life. It is an implicit value denoting @age / @life.

Variables & Attributes Resources

Resources