[Houdini VEX]

Happy Rendering with VEX
- Version 1.1 -

Keita Maeda
December 2000

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 Start-up
VEX Tips
Reference
Feedback

Versions:
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


VEX Sample Codes I

RenderMan shaders taken from RManNotes have been converted into VEX codes. This is just a start. Improve the shader.
  • vexnotes.h
    vexnotes.h is a collection of useful functions such as boolean operations which are not supported in VEX natively. Put this file in the $HOME/vex/include directory and include it in .vfl file:
    # include <vexnotes.h> 
    

  • prman.h
    prman.h contains defines and inline functions which are helpful when porting RenderMan shaders to VEX code. You can find this file in the $HFS / houdini / vex / include directory.
    # include <prman.h> 
    

  • Regular Patterns

  • "Cross" Tile Keyword: pulse()

    crosstile.vfl cross.vfl

  • Which Tile Are We Shading? odd(), even()

    crossweave.vfl

  • Rotating Tiles rotate2d()

    rotcross.vfl

  • Shifting Tiles whichtile(), intersection()

    shiftedblocks.vfl

  • Shape Generation - Rectangles, Disks, Rings and Lines

    rect.vfl disk.vfl
    rings.vfl line.vfl

  • Boolean Operations union(), difference(), intersection()

    moon.vfl

  • Stochastic Patterns
  • Noise (Two-dimensional noise) noise()

    twodnoise.vfl

  • Turblance snoise()

    turb.vfl gcturb.vfl

  • Pure Stochastic Patterns

    rmarble.vfl

  • Displaced Turblence

    dturb.vfl

  • Fire

    fire.vfl

  • Rondomized Rings

    rings.vfl

  • Wood Solid Texture

    notwood.vfl wood.vfl

  • Bombing

    rotblocks.vfl rotblocks3.vfl

    rotblocks4.vfl


  • VEX Sample Codes II

  • Smoke

    smoken.vfl smoke_glow.vfl

  • Displacement

    disp1_2.vfl dmap.vfl

  • Twosides

    twosides.vfl

  • Metaball-blend

    metablend.vfl / metablend.hip.gz (V4.0)

  • Shader Gallery (taken from Digital Lighting: Shader Gallery)

    brick.vfl fin2.vfl

    trackdisp.vfl stained_glass.vfl

    icy.vfl crud.vfl

    jellysurf2.vfl aurora.vfl

    cavity_d.vfl leafveins.vfl

    triples.vfl tidles.vfl

    bub.vfl smoke_glow.vfl

    cloudy.vfl greeny.vfl

    leafcolor.vfl pattern.vfl

    regular.vfl

    window_light.vfl(SESI) batsignal.vfl

    window.vfl window_displ.vfl


  • VEX Sample Codes III (by ShadeTree)

    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.
  • Surface

    beaten.vfl dented.vfl

    st_plastic.vfl lizard.vfl

    camo_desert.vfl chromy.vfl

    st_fire.vfl cloudyforenvmap.vfl

    granite_polished.vfl granite_raw.vfl

    mirrored.vfl refl_metal.vfl

    speckles.vfl tinCeiling.vfl

  • Displacement

    disp_rope.vfl

  • Light

    light_checks.vfl

    light_projector.vfl light_spec_env.vfl

  • Fog (Atomosphere, Volume)

    fog_volume.vfl fog_litshadowed.vfl

  • Shadow

    shad_basic_ray.vfl


  • VEX Sample Codes IV (from SESI)

    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.
  • Surface

    amber.vfl coreglow.vfl

  • Displacement

    bio_surface.vfl, bio_displace.vfl dmapcomp.vfl

  • Fog

    projfog.vfl

  • Shadow

    ubershadow.vfl

  • Cop

    displacev1.vfl varyaddd.vfl

    tilerX.vfl tilerY.vfl

  • Light

    discolight.vfl

  • Pop

    wisp.vfl


  • VEX Sample Codes V (from our customers)

    Here are shader examples from our customers.
  • Surface

    Easy-to-use cartoon-like shader.Tani3toon.vfl


  • Easy Start-up

    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.


    VEX Tips

    Nuff respect to Mark Elendt-san (Side Effects Software Inc.) for a lot of VEX Tips.
  • When converting .sl into the VEX code, firstly include both prman.h and vexnotes.h and modify:
       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)
    
  • The 'mod' function is important when generating periodic patterns. Instead of mod(aa,bb), use:
                        mod(aa,bb)  ->  ((aa)%(bb))
    
    This is defined in prman.h.
  • The 'blend' function, which is defined in vexnotes.h is the same as the 'lerp' function which is supported by VEX.
  • Boolean operations are supported in vexnotes.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))
    
  • The syntax:
        { 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;
    
  • Unlike RenderMan, the Du(x) function returns the non-normalized partial derivative. This means that you do not have to multiply by "du" or "dv". For example:
    #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
     
  • Converts "hsv" color space into "rgb":
        layer_color = rgbtohsv(1, 1, 1); 
    See VEX Color Functions in the VEX Language Guide

  • In user functions, global variables are still visible (unlike RenderMan). This means that the extern keyword is not required for VEX. I'm not sure if RenderMan allows a shader local variable to be visible outside the scope of the shader. If this is the case, then VEX has no mechanism for dealing with this.

    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...

  • The trace function is declared differently in VEX. This is to allow you to query the color, opacity and alpha of the intersected surface.

    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;
        }
    

  • Reference

  • RManNotes
    RenderMan shaders taken from RManNotes have been converted into VEX codes in VEX Sample Codes I.
  • Digital Lighting: Shader Gallery
    Most of the shaders in VEX Sample Codes II have been taken from Digital Lighting: Shader Gallery
  • VEX Tutorial
  • VEX Tutorial(Japanese)
  • VEX Language Guide (distributed with Houdini4.0)

  • Feedback

    Any comments or suggestions appreciated. Please send emails to:

    Keita Maeda ( maeda@estec.nk-exa.co.jp )