write a new VOP in VEX aka “VEX Builder Types”

   10493   10   2
User Avatar
Member
237 posts
Joined: July 2005
Offline
I am interested in working out how to write a new VOP in VEX! And I am stuck just getting the basic in and out of the process. After I work that out I will have fun with the creative bit in between.

Specifically am looking to find out how to write the input and outputs.

If it isn’t possible can somebody tell me? Is it only possible to wire up custom VOP types?

The answer would be best illustrates by showing the VFL code to make up an add VOP, with 2 inputs and one output.
Robert Kelly
User Avatar
Member
941 posts
Joined: July 2005
Offline
meshsmooth
I am interested in working out how to write a new VOP in VEX!
Hi meshsmooth,

You can do it by writing your OP as a context function ( e.g: a surface shader) and then using the “-m” (or “-M”) option to vcc.
For your add example, it would go something like this:

In file myAdd.vfl you'd write:
surface myAdd ( float a=0,b=0; ) {
Cf = a+b;
}

And you compile it like this:
vcc -m myAdd.otl myAdd.vfl

Then you import the resulting otl into Houdini as usual…

Obviously, the inputs are simply the parameters, and the outputs are restricted to the globals that the chosen context function (surface shader in my example) is allowed to modify (for surface shaders these are Cf, Af, and Of – so a max of 3 outputs for that context).

As you can see, there are some limitations to this method, but you can use it as a starting point and modify it inside Vex Builder. It's the only “out-of-the-box” method available to you if you want to write your VOPs using straight VEX (instead of Vex Builder).

Hope that helps.
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
237 posts
Joined: July 2005
Offline
So let me get this striate
If I want to make this

By coding it I cant!!?? I can only wire it up inside a subnet!

And if that is the case that sucks! But if it isn’t how do you write an input for that coded VOP?
Robert Kelly
User Avatar
Member
941 posts
Joined: July 2005
Offline
meshsmooth
So let me get this striate
If I want to make this
By coding it I cant!!?? I can only wire it up inside a subnet!

Did you try the example I gave you?
It creates a VOP that takes two inputs, adds them, and puts the result to a single output. This is exactly what your picture shows. So…..

And if that is the case that sucks! But if it isn’t how do you write an input for that coded VOP?

"…how do you write an input for that coded VOP?…"

I'm having trouble parsing that bit… if it's a coded vop, then you write the output by coding it, of course. Here, writing and coding refer to the same action – typing some VEX code into a file that will eventually get compiled to create a VOP.
I suspect we may be talking about different things here…


It's not the best method in the world, no. It has limitations: i.e. you can't make a VOP with 100 outputs this way (not that you'd ever want to, but…). And there are some other issues that have been covered in the forum before, but number of *inputs* is definitely not one of them.

Let me see if I can make it really clear. Here's some CODE that will create a VOP wthat takes TWO INPUTS, adds them, and puts the result out to ONE OUTPUT.


surface my_new_hand_coded_vop ( vector pos=0,vel=0) {
Cf = pos+vel;
}

But to see this vop, you must compile it first. (see my first post for how to do that)
Maybe you mean something different when you say “code”?, could that be the confusion?

If I'm misinterpreting your question, then how about posting an example of exactly how you'd see your “code”, what does it look like in your mind (assuming this is a perfect world and you could code your VOP your way), this could help with some of the confusion.

Cheers!
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
237 posts
Joined: July 2005
Offline
“…how do you write an input for that coded VOP…”
What i mean is when you code the VOP how do you make so you can wire into it…. or can i not do it. My use of the words code and write confused the issue.

i compiled the code and it was only accessible in a vex shading operator and not a vex geometry operator, where i want to use it. When it was inside the shading operator it didn’t have any inputs or outputs or any way to access it … I am assuming you need to use the variable of a and b and in this case the otherVal as well

surface myAdd ( float a=0,b=0; ) {
otherVal = a+b;
}

Is this to encourage people to get the SDK

I just want to make my own version of “aanoise” or any other idea that would be easier to code than wire, that I can insert into each VEX builder context. (Or just the geometry operator, if it is specific to that)

Sorry if I am being a pain in the ass just making shore that this is a road block that has to be worked around or it is just the current limit of my knowledge and there is a highway of possibility right there to discover.
Robert Kelly
User Avatar
Member
237 posts
Joined: July 2005
Offline


vop my_new_hand_coded_vop ( float a, b)
{
#wireInput a // create the input wire of a (in the picture P)
#wireInput b // create the input wire of b (in the picture v)

float sum = 0;
a + b = sum

#wireOutput sum // create the output wire of sum
}


and look something like this at the end


Once I have this worked out i can replace the simple add with maybe a noise, some clamping, a comparison, or what ever I can think to code up.
Robert Kelly
User Avatar
Member
941 posts
Joined: July 2005
Offline
Hi Robert,

meshsmooth
Sorry if I am being a pain in the ass just making shore that this is a road block that has to be worked around or it is just the current limit of my knowledge and there is a highway of possibility right there to discover.
Yes; there *is* a “highway of possibility right there to discover”, and no, you *don't* need the HDK to get to the on-ramp…. but a ramp there is

OK; there's a fair bit of confusion here (and please don't take that the wrong way, this is a confusing subject for everyone; period). So let's take it one step at a time, because if I write one long messagge, it'll just confuse things even more.

Please do these steps exactly as written here, and hopefully we'll both arrive at the same result:

1. This is the first time you mention what type of VOP you wanted to build, so let's make a SOP VOP. Copy-paste the following into your favourite text editor (don't type it, copy it):

#define VOP_OP
#define VOP_SOP

#pragma opname mysopvop
#pragma oplabel “My Surface Vop”
#pragma opmininputs 1
#pragma opmaxinputs 1
#pragma label voff “Vector Offset”
#pragma label foff “Float Offset”


sop mysopvop(vector voff = 0; float foff = 0)
{
P += voff + foff;
}


2. Make sure there's nothing but those lines in your editor, and save it to a file – let's call it mysopvop.vfl

3. Change directory to wherever you saved mysopvop.vfl and run vcc *exactly* like this:
vcc -m mysopvop.otl mysopvop.vfl

4. Make sure that vcc created a file called mysopvop.otl, then start houdini, go to “File->Install Operator Library…”, and install the otl we just created.

5. Open up a VexBuilder pane and add a “Vex Geometry Operator” vopnet. Go into the vopnet and add (Tab->select) the VOP called “My Surface Vop”.


What do you see?


Again; just doing it one step at a time. We have to be able to get at least this far before we can keep talking, though

Let me know how it goes.
P.S: It's important you copy the above code *exactly* as it is. Don't even change the spaces! Just humour me for now (there is a bug with vcc that has to do with how you type something, but I don't want to get into that right now – let's do this much first)
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
237 posts
Joined: July 2005
Offline
IT worked!!

now i can use that as a template for other vops
Robert Kelly
User Avatar
Member
237 posts
Joined: July 2005
Offline
But how do I export a value that isn’t a global variable like the variable Robs_output


#define VOP_OP
#define VOP_SOP

#pragma opname mysopvop
#pragma oplabel “My test Vop”
#pragma opmininputs 1
#pragma opmaxinputs 1
#pragma label voff “Vector Offset”
#pragma label foff “Float Offset”
#pragma label zero “an int currently zero”

sop mysopvop(vector voff = 0; float foff = 0; int zero = 0)
{
vector out = 0;
out = voff + foff;
}


Is there some documentation I should be reading…? I haven’t found much on this topic.
Robert Kelly
User Avatar
Member
2199 posts
Joined: July 2005
Online
If you are looking for easier ways, just make a subnet that does what you want with all the inputs you need. Inside the subnet create a network and wire the outputs you need into the little white “next…” buttons on the suboutput1 node. Then go back up a level to the subnet node and right click on it and do “Create Type From…”

If you want to be able to code it instead, then go to the Houdini file menu, top right, and go to “New operator type…” select “Vex builder type” name it what you like and click accept, this will then bring up the type properties dialog allowing you to set any inputs and outputs you need, you can then add the code for these in the vex code tab (inner code) just use the names that you created in the input/output tab, but put a $ sign in front of them.

eg
$output = $input1 + $input2;

If you want parameters for these inputs and outputs to appear in the dialog for the VOP then you need to create those too, do this on the parameters tab. Again make sure you use the same names as in the input/output tab, only this time you don't need the $ sign.

This is just the bear bones, but hopefully it will make much more sense if you try it. Also try looking at the type properties for already existing vops,
you should see a lot of them have been created the same way.

Si
The trick is finding just the right hammer for every screw
User Avatar
Member
344 posts
Joined: July 2005
Offline
Looky what our friend export can do

#define VOP_OP
#define VOP_SOP

#pragma opname mysopvop
#pragma oplabel “My test Vop”
#pragma opmininputs 1
#pragma opmaxinputs 1
#pragma label voff “Vector Offset”
#pragma label foff “Float Offset”
#pragma label zero “an int currently zero”

sop mysopvop(vector voff = 0; float foff = 0; int zero = 0; export vector out = 0
{
out = voff + foff;
}

Use that code and ‘out’ will show up as an output on your shiny new VOP. Unfortunately it also shows up as an input. I don't know what if anything you can do to change that. Maybe someone here does.
  • Quick Links