Using Vex inside Shader/mat context

   789   5   4
User Avatar
Member
4 posts
Joined: Dec. 2017
Offline
Hi,

i am trying to create my own displacement shader and I have already set up quite a few VOP nodes. However I would much rather write code, like the wrangle nodes in the /obj context, and pipe the position and normal results back out so that i can use them on a output->collect node.

I guessing this is possible but I couldn't figure out how. So it would be great if someone could point me in the right direction. Is there a tutorial which creates a BSDF in Vex Code or something similar, that would probably be very helpful

Thanks in advance,

Knork
User Avatar
Member
1460 posts
Joined: Sept. 2011
Offline
The source code for many common bsdf are present in the houdini install directory. Look inside vex/CVex for bsdf shader source (.vfl)

As for creating code snippets within an existing material vop network, you can either use an inline or snippet vop. The two behave slightly differently. Snippet creates a void function that is automatically moved out of the main shader, and called inline. An inline node creates code that is directly inlined, so you have to worry about variable name collisions and scope. This is avoided by prefixing variable names with $, i.e. $mypos = P; Alternatively, you can create a new vop type that derives from code, these follow the behavior of inlines, but with the possibility of getting default values for disconnected inputs from the parameters on the node. To go even more pure code, your entire shader can be defined as a .vfl file, and compiled into an hda or .vex file in your houdini path. There are many examples of these in the vex/Surface folder of the houdini install. You use the command line program ‘vcc,’ which is similar to ‘gcc’ for generic programs, to compile the shader source to a usable node.

Creating a new bsdf cannot be done inline, as they are external shaders that have to be created separately from the the material surface shader. The are also a different context, the CVEX context as opposed to Surface/Displace used by the material.
User Avatar
Staff
962 posts
Joined: July 2005
Offline
You can use Snippet VOP, which is what wrangle SOPs are based on.

You can also used an Inline VOP for quick injection of VEX code.

As for creation of BSDFs in Vex, you can manipulate existing BSDFs (created by Diffuse or Specular VOPs) using standard arithmetic (add, sub, mult, div VOPs).

If you need to define a custom BSDF from scratch, you can take a look at http://www.sidefx.com/docs/houdini/vex/functions/cvex_bsdf.html [www.sidefx.com]
User Avatar
Member
4 posts
Joined: Dec. 2017
Offline
Thank you both your're answers have been tremendously helpful to me! I am looking forward to exploring these new options and now actually writing my own shader .
User Avatar
Member
3 posts
Joined: Jan. 2016
Offline
Quick question:

When I write/compile .vfl shaders, they appear in the ‘SHOP’ context rather than the ‘mat’ and material builder areas of houdini.

How can we write shaders that can act as material VOPs like all the other nodes in the material builder?

Any info is appreciated.

-jez
User Avatar
Member
1460 posts
Joined: Sept. 2011
Offline
jeremykhardin
Quick question:

When I write/compile .vfl shaders, they appear in the ‘SHOP’ context rather than the ‘mat’ and material builder areas of houdini.

How can we write shaders that can act as material VOPs like all the other nodes in the material builder?

Any info is appreciated.

-jez

You can use
#pragma optable vop
but, it probably doesn't do what you want. The pragma tells vcc to create a vop hda that ‘imports’ your shader from vfl/vex and wraps it in a vop node. You only get outputs from ‘export’ variables, and inputs from other inputs in the shader. No ‘surface’/'displace' etc shader connections are created, since the vop is merely invoking the shader as a function.

There currently is no way to make a proper shader from vfl source that works in the mat context.
  • Quick Links