[SESI logo]

VEX Language Reference - Version 6.5

Side Effects Software Inc. 2003

VEX Examples

Many examples may be found in the Houdini distribution by placing a VEX based node and then examining the VEX code by accessing the "Type properties..." from the tile menu entry. Other example source may be found on the web.

This document contains some additional notes on writing efficient VEX code.


The Constant Color Cop

The function could be written this way: cop constant(vector clr=1; float alpha=1) { R = clr.r; G = clr.g; B = clr.b; A = alpha; } However, it is better to use the high-efficiency assign functions. cop constant(vector clr=1; float alpha=1) { assign(R, G, B, clr); A = alpha; }

A User Noise Function

This example defines a two user functions which generate normalized multiple octaves of Perlin noise. float myfperlin3d(vector pos; int octaves; float rough) { int i; float nval; vector pp; float result, sum, scale; // Because parameters are passed by reference, we don't really // want to modify the parameters value. Therefore, we copy it // to a temporary variable. pp = pos; scale = 1; sum = 0; result = 0; for (i = 0; i <= octaves; i++) { result += noise(pp); sum += scale; pp *= 2; scale *= rough; } return result / sum; } float myfperlin1d(float pos; int octaves; float rough) { int i; float nval; float pp; float result, sum, scale; // Because parameters are passed by reference, we don't really // want to modify the parameters value. Therefore, we copy it // to a temporary variable. pp = pos; scale = 1; sum = 0; result = 0; for (i = 0; i <= octaves; i++) { result += noise(pp); sum += scale; pp *= 2; scale *= rough; } return result / sum; } It is possible to use #define macros to encode the contents of the function and simply call the macro to generate vector or other dimensions of noise.



Copyright © 1999-2003 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7