
Happy Rendering with VEX
Keita Maeda 
Contents:
VEX Sample Codes I
VEX Sample Codes II
VEX Sample Codes III (by ShadeTree)
VEX Sample Codes IV (from SESI)
VEX Sample Codes V (from our customers)
VEX Library (all source codes and .hips)
Easy Startup
VEX Tips
Reference
FeedbackVersions:
Version 1.1: December 2000  several examples from SESI website
Version 1.0: October 2000  ShadeTree examples and VEX Library have been added.
Version 0.9: January 2000
RenderMan shaders taken from RManNotes have been converted into VEX codes. This is just a start. Improve the shader.
metablend.vfl / metablend.hip.gz (V4.0)
trackdisp.vfl stained_glass.vfl
window_light.vfl(SESI) batsignal.vfl
Here are shader examples created by using ShadeTree (from Cinema Graphics Inc.) for VMantra. ShadeTree is an interactive shader language authoring tool and is able to export ShaderSource(.vfl), Compiled Shader (.vex), Render Interface (.ifd) and Shader Interface (.ds). ShadeTree also lets you see what your shader will look like by using test render button. Some of the below shaders can be compiled if you delete #include "STREE_math.h" statement.
st_fire.vfl cloudyforenvmap.vfl
Here are shader examples taken from SESI website  The VEX Exchange section. As some of them (such as Fog, Shadow, Cop) are hard to understand only by looking at the small images, please read #pragma help in .vfl files for details.
Here are shader examples from our customers.
Easytouse cartoonlike shader.Tani3toon.vfl
To preview your VEX shader quickly, start Houdini and place the Generic surface SHOP for the surface shader. Write a vex name with parameters (stained_glass or stained_glass.vex) in the VEX Mantra field and go render with vmantra.
Nuff respect to Mark Elendtsan (Side Effects Software Inc.) for a lot of VEX Tips.
color red = color (1, 0, 0) > vector red = {1,0,0} d = distance(center, {s, t, 0}) > d = distance(center, set(s, t, 0)) (A.B) > dot(A,B) (A^B) > cross(A,B)
mod(aa,bb) > ((aa)%(bb))This is defined in prman.h.
#define intersection(a,b) ((a) * (b)) #define union(a,b) ((a) + (b)  (a) * (b)) #define difference(a,b) ((a)  (a) * (b)) #define complement(a) (1  (a))
{ x, y, z }defines a vector "constant". This means that each of x, y, z must be a constant. If any of these are variables, then you must use the "set" instruction:
center = {.5, .5, 0}; d = distance(center, set(s, t, 0)); Or: target = set(s, t, 0); d = distance(center, target);The set instruction is almost 3 times faster than doing:
target.x = s; target.y = t; target.z = 0;
#ifdef __vex #define filterwidth(x) (max(abs(Du(x)) + (Dv(x)),MINFILTERWIDTH)) #else #define filterwidth(x) (max(abs(Du(x)*du) + (Dv(x)*dv),MINFILTERWIDTH)) #endif
layer_color = rgbtohsv(1, 1, 1);See VEX Color Functions in the VEX Language Guide
This code should work just fine with VEX:
vector shader_space() { return wt_space(P); } surface test() { Cf = noise(shader_space()); }However, VEX does not support nested function definitions, so the extern keyword is not really pertinent...
It's possible to write:
color prman_trace(point P, point R) { color cf, of; float af; trace(cf, of, af, P, R, 0.005, 1); return cf; }