Home » 3D, Houdini

Writing a VEX shader for Houdini

22 May 2007 109,845 views 18 Comments

Using the VOP network as a shader

Now that we’ve created the VEX network with the code to implement the shader, we have to turn it into a shader so that we can apply it to geometry. This is exactly what the next step does.

  1. Press "u" to step out of the VEX shader.
  2. Right click on the "lightWrap" node and select "Create New Shop From Vop Network".

You could have also created a SHOP digital asset from the VEX network by selecting "Create Shop Type From Vop Network", and there may be situations where you would want to do that.

Next we’ll create a sphere and apply the shader to it.

  1. Choose Objects as current context (i.e. /obj/->)
  2. Press Tab. Select "Geometry". Rename the new node "sphere".
  3. Press "i" or <Enter> to navigate inside and delete the default "file1" node.
  4. Press Tab. Select "Sphere".
  5. In parameters, change "Primitive Type" to "Mesh", and "Rows" and "Columns" to "64".
  6. Press "u" to step out of the geometry node.
  7. Go to the "Shading" tab of the "sphere" node and use the "+" button of the "SHOP surface" parameter to select the "lightWrap1" shader inside the "shop" branch.
  8. In the main viewport press "h" to home the view on the sphere.

We’ll need to add a light to view the effect properly.

  1. Press Tab. Select "Light".
  2. In parameters, change the "Translate" on the "Transform" tab of "light1" to 10, 10, 10. Set the "Light Color" on the "Illumination" tab to white.

Finally, do the following to view the shader and to tweak the settings.

  1. In the main window, change the view drawing style to "VEX Shaded".
  2. Go to the main 3D window and change the pane linking from (1) to (2) to disconnect it from the network and parameters pane.
  3. In the network pane, change the context to "SHOPs".
  4. Play with the "Light Wrap" parameter to see how it affects the shaded surface. Reset it back to "0" when you have finished.

The light wrap shader

The next page shows how to drive the shader from attributes stored on the geometry itself.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)


  • SG said:

    I tried this in h10 but no luck. Any idea what might have to change>?

  • AndyN (author) said:

    Hmmm. No, not off the top of my head. I should probably update this tutorial for version 10 anyway.

    I’ll take a look and get back to you, or you can send me the hip file if you like. I’ll ping you my email address in a sec.

  • SG said:

    Hey – thnks.
    Im pondering over it now. The VOP errors at the moment, may be the inline code, but i have no way of
    error checking it. Im trying nodes instead of code to see if this fixes it.

  • SG said:

    my gaff, its working just fine in H10 – i think i gave the wrap a constant instead of a parameter.
    Useful little vop – thanks.

  • AndyN (author) said:

    Cool, glad you got it working πŸ™‚

  • Danil said:

    Hey guys,

    I could not find this option:
    43. Go to the “Shading” tab of the “sphere” node and use the “+” button of the “SHOP surface” parameter to select the “lightWrap1” shader inside the “shop” branch.

    I have a sphere node selected and i am in Shading where Sampling and Dicing is but i cant find “”+” button of the “SHOP surface” parameter to select the “lightWrap1” shader inside the “shop” branch.” πŸ™

    Any ideas?

  • AndyN (author) said:

    Hi Danil,

    Yep, this tutorial is quite confusing if you’re trying to follow it in the latest version of Houdini.

    The problem is that the interface and method of shader assignment in version 10 has changed. Basically, you need to set up a material with the shader in and assign it to the object on the Material tab of the object. If you’re not sure how to do that yet, then you should probably investigate some other more fundamental tutorials before trying to decipher this one.

    I’ll try and get round to updating this tutorial soon.



  • Danil said:

    Hi AndyN,

    Ohhh now i got it πŸ™‚ Thanks for the explanation. Shader is working like a charm, i am actually using Houdini 9 here πŸ™‚ and trying to figure out last few steps from 50, and on.

    Also just wanted to say, very, very and i mean very good tutorial. I have been looking for something like that for god knows how long. This does not get any better that that. I hope to see any tutorials soon πŸ™‚ Maybe something about custom made SSS πŸ™‚

    Thank you.

  • Danil said:

    btw, by any chance do you know what would be the best way to output this as one of AOV in mantra render ?

  • AndyN (author) said:

    I’ve not needed to do that much, but I believe you can just export the parameter from inside the VOP network using a Parameter VOP with it set to Export Always. You can then pick it up from inside the ROP using the image planes.

  • Danil said:

    Hey AndyN.
    One more question, say i want to have light ramp happening only on the edge of the sphere. Like, something that would represent the light coming from the back side of the geo and then use Light Wrap to control how much light gets spieled over. I know it maya it would involved using facing ratio node that would use normal of the geo to figure out what is what.

  • AndyN (author) said:

    I’m not quite sure what you’re after, but you can generate a “facing ratio” value by doing the dot product of the Surface Normal (N) and the Eye Ray Vector (I) both of which you can get from the Global Parameters node inside the VOP network. You can use that to drive a ramp parameter.

  • kerem said:


    “We then create a temporary floating point variable called $t (it could be called anything, I just picked “t”) and take the dot product of L (the incoming eye ray) and N (the normal vector of the surface being shaded).”

    Is not “L” light vector?

  • AndyN (author) said:

    Hi Kerem. Yes, you’re exactly right. I’ve fixed it.

    Thanks for pointing it out.

  • Alex said:

    Hi Andy,

    Great tutorial you’ve written, I like the breakdowns and explanations especially. I know this was written for H9, but I’m using H11.1 and I’m running into a minor problem involving the viewport display of the shader.

    I’ve managed to get the material assigned to the sphere and can see the effect of the light wrap and diffuse color changes if I do a render or render region preview, but I can’t seem to get it to display in the viewport. I added in the OGL render parameters and can get the diffuse color to update, but can’t seem to figure out how to get the light wrap parameter to affect anything in the viewport. I don’t have this VEX shaded mode.

    Any help would be appreciated,

  • Alex said:

    hi Andy,

    OK, never mind about the previous question after reading the final page about requiring a render to see the effect…

    I was also wondering if this light wrap setting is easy to implement in a PBR shader like the default mantra surface shader in H11. I’m not sure where to insert it, must be somewhere in the surfaceModel?


  • AndyN (author) said:

    Hi Alex,
    Glad you figured it out. Yep, I could do with updating this tutorial, it’s looking a little dated!

    As for the PBR, that’s not something I’ve spent a lot of time looking in to, so I’m probably not the best person to ask. Sorry!


  • Alex said:

    Hi Andy,

    No worries, I posted a question to the sidefx forums and we’ll see if it turns anything up. Some of the PBR stuff isn’t well documented in my opinion.

    thanks again,