VOP inline code

   8903   6   1
User Avatar
Member
345 posts
Joined:
Offline
Hi there,

I'm looking for any example how to embed a VEX code inside VOPs. My aim is to reuse choppy water example as a displacement in the material shader builder. Since in H11 most of the old materials have gone and subnetworks were replaced by vopmaterial node. I'm very interested to see recommended shading workflow, the displacements in particular.
User Avatar
Member
65 posts
Joined: May 2009
Offline
Hi Kuba,

unfortunately I have no definitive answer for your questions, but I'm also interested.

Maybe I'm wrong but I guess the ‘VEX builder type’ found in the ‘new operator type..’ window may serve this purpose. Unfortunately it's seems to be completely undocumented.

I don't know what the ‘outer’ and ‘inner’ code sections are for, and I don't know how can you define reusable context agnostic functions in VEX.

Regards
Mate
User Avatar
Member
45 posts
Joined: June 2009
Offline
Hi,
here's attached a simple example using Inline Vex Code.
It isn't exactly what you asked for but I hope it can be useful in some way.

Attachments:
inline_example.hipnc (59.5 KB)

User Avatar
Member
678 posts
Joined: July 2005
Offline
john_z
Hi,
here's attached a simple example using Inline Vex Code.
It isn't exactly what you asked for but I hope it can be useful in some way.

Couple notes here. You don't have to use $ every time you create variable. You use it only when you want acces some parameter that is connected or created on actual node that you placing this code. So when you created “int i” don't use $i since you are not importing it from somewhere, its just variable that you created here. Also when you using global P and N that are not modified you don't have to import them from your input, just write P and it will work.

Here is a little modified your code.


float hump = 0.0;
float cf = $freq;

int i = 0;
for(; i < $iter; i++)
{
hump += abs(0.5 - noise($crinckle * cf * P))/cf;
cf *= $scale;
}

$outPos = 2 * (P - N * hump * $km);



gadfly16
I don't know what the ‘outer’ and ‘inner’ code sections are for, and I don't know how can you define reusable context agnostic functions in VEX.

Regards
Mate

Outer part is where you can create your functions and then call them in inner part. You can't create functions in inner part.
Edited by - Sept. 9, 2010 10:29:32
User Avatar
Member
45 posts
Joined: June 2009
Offline
Swann_
Couple notes here. You don't have to use $ every time you create variable. You use it only when you want acces some parameter that is connected or created on actual node that you placing this code. So when you created “int i” don't use $i since you are not importing it from somewhere, its just variable that you created here. Also when you using global P and N that are not modified you don't have to import them from your input, just write P and it will work.

Thank you Swann_ for your clarification.

j.
User Avatar
Member
941 posts
Joined: July 2005
Offline
Swann_
Couple notes here. You don't have to use $ every time you create variable. You use it only when you want acces some parameter that is connected or created on actual node that you placing this code. So when you created “int i” don't use $i since you are not importing it from somewhere, its just variable that you created here. Also when you using global P and N that are not modified you don't have to import them from your input, just write P and it will work.

I don't think that's a very good idea. Omitting the ‘$’ from local variables (whether in an inline VOP or an ‘inner’ code section of a VEX VOP) is a pretty dangerous thing to do.
The ‘$’ is there to avoid name clashes – it ensures the name that follows it will be made unique within the current scope (the body of the inline VOP, for example). Without the ‘$’, the name will be injected into the body of the context function as-is. This is OK if (and only if) there is a single instance of your inline VOP (or your VEX VOP) within the VOP network. The moment you have more than one copy of the same inline VOP (or more than one instance of your VEX VOP) in the same network, you'll get warnings from vcc complaining that there are “Multiple declarations of the variable” and the code will break.
To see this in action, just omit the ‘$’ from a local variable declaration (and all locations where it's used) in some inline VOP, then copy-paste the VOP a few times (and wire the copies so they get used in the network, otherwise they'll get ignored, which will mask the problem). You should see a lot of warning messages the moment the network gets cooked.

So, I'd recommend putting ‘$’ in front of all local symbols (that includes local variables).
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
678 posts
Joined: July 2005
Offline
It was just a suggestion based on what I saw in the file. But mulitiple copies of the same VOP are another scenario and it's better to learn beginers good practices than bad practices that make them frustrated .


BTW. Kuba, have you seen tutorial about creating own VOPS in OldSchool Blog part of this site ? http://www.sidefx.com/index.php?option=com_content&task=blogcategory&id=115&Itemid=216 [sidefx.com]
  • Quick Links