Not understanding meaing of vex function argument

   3943   6   0
User Avatar
Member
2168 posts
Joined: Sept. 2015
Offline
Hello,

I was hoping someone might be able to explain or show how a specific vex argument option might be used.

There's a number of vex functions that have similar options like setpointattrib:

In these functions I understand and have used the different options like “set”, “add”, and “mult”.

But I don't understand either “min” or “max” as it's explained in the docs, for say “max”:

Set the attribute to the maximum of itself and the value.

I've tried playing with the function and this option and I can't seem to get any results that suggests to me how it may be used.

I mean if I write ;

setprimattrib(geoself(), “New_Value”, 0, 2.0, “max”);

It will always set the value to the second last argument ( 2.0 in this case ).

But then why use max when “set” does the same thing.

So I thought maybe it works like a clamp;

setprimattrib(geoself(), “New_Value”, 0, 2.1, “set”);
setprimattrib(geoself(), “New_Value”, 0, 2.0, “max”);// Thinking it might reduce it to the “max”, but in testing it stays at 2.1
Edited by BabaJ - April 26, 2017 15:14:16
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Hello dude.
If I'm not wrong it means when you try to put a attribute in max mode, before any changes VEX tries to compare current value which you pass as function argument and previous value and that changes with greater value.
Edited by Nima - April 26, 2017 16:09:14
User Avatar
Staff
6813 posts
Joined: July 2005
Offline
Try this

setprimattrib(geoself(), New_Value, 0, 2.0, max);
setprimattrib(geoself(), New_Value, 0, 1.0, max);

And compare with “set”.
User Avatar
Member
2168 posts
Joined: Sept. 2015
Offline
Ok Guys,

I understand now.

My shortsightedness was because I was working on some code in detail mode in my wrangle.

And in detail mode you always have to use a function to set the attribute of say in this case, a point attribute.

So it seemed the “max” option had no use.

But when now playing around with it in run over mode, I see it's use.

Thanks very much for the tip off.

Nice to learn something new everyday in Houdini
User Avatar
Member
8179 posts
Joined: Sept. 2011
Online
It doesn't matter what the ‘runover’ is set to, setattrib() will use the set mode when setting the value. This is useful when the attribute already exists on the incoming geometry stream, such as in a solver. For example, you could record an event by storing the event state to an attribute using mode ‘max,’ and subsequent solver steps where the event state is no longer true will not decrease the value.
User Avatar
Member
2168 posts
Joined: Sept. 2015
Offline
Interesting…I will have to remember this if I ever am using a solver.

I thought what your suggestion might be a way to “store” a value and make it persist across subsequent frames, acting like a “global”.

But this does not work and it makes no difference whether I use “set” or “max”. So in the context I was looking at it still makes no difference.

But thanks for the tip. Something that could definitely be usefull.

Just to be clear..the context I'm was thinking of is frame/time event dependant, e.g.:

// set Detail(only once)
if(@Frame == 25){setprimattrib(geoself(), "New_Value", 0, 2.0, "max");}
Edited by BabaJ - April 27, 2017 14:29:13
User Avatar
Member
9416 posts
Joined: July 2007
Offline
I would avoid using this if you are changing the value of current point, prim or detail while iterating in respective mode, as it's slower and not necessary
however you can use it in many other situations
like iterating over closest points or neighbors of first input and setting their value using “add” or “max”, …
this can have sometimes advantages over gathering values from neighbors, but it really needs to be necessary as by using setattrib() you are queuing those commands on a single thread postprocess so it will be slower than gathering which is multithreaded

or you can use it for promoting an attribute, etc…
Edited by tamte - April 27, 2017 22:49:27
Tomas Slancik
CG Supervisor
Framestore, NY
  • Quick Links