Change Particle Color based on Life (VEX)

   15516   15   2
User Avatar
Member
767 posts
Joined: April 2014
Offline
I want to change the particles based on life in the POPVelocity nested within a POPNet as a VEXpression I've tried numerous equations but the one that I'll put attention too is the following;

@life / @Cd;
@life / random(@Cd);

Should I be making a point VOP or an AttributeCreate at SOP level ?
【T】【C】【S】
User Avatar
Member
2555 posts
Joined: June 2008
Offline
Well @life and @age are both just floats so the best you can hope for is a greyscale color, or a brightness adjustment. It makes a little more sense to adjust by @age not @life. Life is a fixed value which is the length of the life in seconds. While @age changes per frame and is the current age up till the end of @life.

Simple VEX variations in a wrangle should set the color for you.
float life_as_percent = @age/@life;   / Really just 0-1 not a percent.
 
// Set color by age.
v@Cd = set(life_as_percent,life_as_percent,life_as_percent);
// Set color by life.
v@Cd = set(@life,@life,@life);
// Age only red channel.
v@Cd = set(life_as_percent,@life,@life);
// Age red, random green.
v@Cd = set(life_as_percent,random(@ptnum),@life);
Edited by Enivob - Oct. 9, 2016 20:31:26
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
767 posts
Joined: April 2014
Offline
v@Cd = set(life_as_percent,life_as_percent,life_as_percent)

float life_as_percent = @age;
v@Cd = set(life_as_percent,life_as_percent,life_as_percent);

float life_as_percent = @age;
v@Cd = set(0.5,0.3,0.3);

The above doesn't work, although if I'm doing a silly mistake ?
Edited by _Christopher_ - Oct. 9, 2016 22:43:17
【T】【C】【S】
User Avatar
Member
252 posts
Joined:
Offline
Do you have a sample file we could look at? Your first code block is missing a semi-colon “;”

You can also use (normalized age):
@nage
It is the same value you would get from
@age/@life

I attached a very simple sample scene.. you can also see a usage of a ramp parameter for finer control.
H15.5.607 Indie

Attachments:
H15_normalized_age_color.hiplc (612.8 KB)

User Avatar
Member
2555 posts
Joined: June 2008
Offline
Nice example file and thanks for the tip on @nage. Where did you find this information? When I middle click on the particle source I don't see @nage present in the list of point attributes? Are there other normalized variables available as well?
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
767 posts
Joined: April 2014
Offline
jlim
Do you have a sample file we could look at? Your first code block is missing a semi-colon “;”

You can also use (normalized age):
@nage
It is the same value you would get from
@age/@life

I attached a very simple sample scene.. you can also see a usage of a ramp parameter for finer control.
H15.5.607 Indie

I attached my Particle Velocity VEX Scene; there may be some extra a code in the Velocity VEXpression that just me experimenting, as to why it wasn't working.

Little change to the code, which the third line doesn't even apply a randomize colors to the particles ?

float life_as_percent = @age;
//@Cd = set(life_as_percent,0,0);
@Cd / random(@age);
Edited by _Christopher_ - Oct. 10, 2016 12:02:29

Attachments:
Particle_VEX.hipnc (204.8 KB)

【T】【C】【S】
User Avatar
Member
252 posts
Joined:
Offline
@Christopher:
I looked at your file. The error was because you were trying to set the color (@Cd) attribute inside the POP Velocity VEXpression. If you want to set the color attribute, you will need to use POP Wrangle or POP VOP.

If you want to apply random colors, try this instead.
@Cd = random(@ptnum);

Anyways, I've uploaded a hip file for you to look at

@Enivob:
I found the @nage info here:
https://www.sidefx.com/docs/houdini/dopparticles/differences [sidefx.com]
I'm not sure if there are any other normalized values available in there.

Attachments:
Particle_VEX_v2.hipnc (547.3 KB)

User Avatar
Member
767 posts
Joined: April 2014
Offline
I was hoping one could have quite a bit of control with VEX in the POP Velocity node; it doesn't appear so. What can you do with VEX in the Velocity node ?
【T】【C】【S】
User Avatar
Member
252 posts
Joined:
Offline
Upon dropping a POP velocity DOP, leaving the VEXpression empty, you can set the velocity (v) attribute for the particles directly. Overwriting any existing ones from up the chain.

So if you type in a value to the Velocity parameter like: 0, 1, 0 …particles will move up. But there's not much else you can do, like vary the speed for each particle.

That is where VEXpressions could come in. It will let you use VEX to manipulate the parameter values.

Keyword is PARAMETER values. Not ATTRIBUTE values.

In this case, it will allow you to vary or override the Velocity PARAMETER value (Not the velocity ATTRIBUTE - although after processing the VEX code, it will eventually write to the particle's velocity attribute).

I've attached a sample usage of VEXpressions in a POP Velocity. It reads in some custom attributes, and uses those to set the velocity parameter. You can also see here how you can set the color from within the VEXpression, although I don't fully recommend that method only due to the fact that it can be quite a lengthy function to type And the attribute in question (@Cd) should already exist for it to work.

Lastly, you can have a more detailed info regarding this topic by reading through it here:
https://www.sidefx.com/docs/houdini/dopparticles/vexpressions [sidefx.com]

I hope this helps

H15.5.607 Indie

Attachments:
H15_velocity_vexpression.hiplc (575.3 KB)

User Avatar
Member
767 posts
Joined: April 2014
Offline
jlim
Upon dropping a POP velocity DOP, leaving the VEXpression empty, you can set the velocity (v) attribute for the particles directly. Overwriting any existing ones from up the chain.

So if you type in a value to the Velocity parameter like: 0, 1, 0 …particles will move up. But there's not much else you can do, like vary the speed for each particle.

That is where VEXpressions could come in. It will let you use VEX to manipulate the parameter values.

Keyword is PARAMETER values. Not ATTRIBUTE values.

In this case, it will allow you to vary or override the Velocity PARAMETER value (Not the velocity ATTRIBUTE - although after processing the VEX code, it will eventually write to the particle's velocity attribute).

I've attached a sample usage of VEXpressions in a POP Velocity. It reads in some custom attributes, and uses those to set the velocity parameter. You can also see here how you can set the color from within the VEXpression, although I don't fully recommend that method only due to the fact that it can be quite a lengthy function to type And the attribute in question (@Cd) should already exist for it to work.

Lastly, you can have a more detailed info regarding this topic by reading through it here:
https://www.sidefx.com/docs/houdini/dopparticles/vexpressions [sidefx.com]

I hope this helps

H15.5.607 Indie


POP Velocity are quasi attributes, rather called Parameters; is there a list of parameters I can use in POP Velocity ?
The page you linked shows one snippet of code; windresist *= rand(@id); Placing this VEX code into a POP Velocity does nothing; which is why I ask is there a Parameter list ?

You have to bind the Attribute VOP then you can call the Attribute within the POP Velocity but it must be binded, correct ?

If I understand, parameters in your explanation would be using VOPS ?

As an alternative could you use a Wrangler (AttributeWrangler /PointWrangler) at SOP level and write out what's in VOP in the Wrangler then use that in the VEX POPVelocity ?
Edited by _Christopher_ - Oct. 11, 2016 00:27:27
【T】【C】【S】
User Avatar
Member
252 posts
Joined:
Offline
Christopher R
…is there a list of parameters I can use in POP Velocity ?
Yes, as mentioned on the docs link from above, there is a drop-down menu on the side of a VEXpression, choose Pass Through to see the valid paramaters for the current POP DOP.

Christopher R
You have to bind the Attribute VOP then you can call the Attribute within the POP Velocity but it must be binded, correct ?
What do you mean by "it must be binded? Are you referring to the Data Bindings tabs?
If you want to call Attributes within the POP Velocity.. the attribute should first exist.

Christopher R
If I understand, parameters in your explanation would be using VOPS ?
Nope. Parameters are what you see in the UI. When you hover over a parameter, it would show its name (in smallcase) and a description. That name is what you would use inside a VEXpression.

Christopher R
As an alternative could you use a Wrangler (AttributeWrangler /PointWrangler) at SOP level and write out what's in VOP in the Wrangler then use that in the VEX POPVelocity ?
Yes, it is exactly what I did on the last sample file I uploaded (H15_velocity_vexpression.hiplc [sidefx.com])
The attributes @myNoise and @myRamp were all created in SOPs level. Then POP Velocity was able to read those.

I have attached an image which hopefully would explain the parts a bit better.

I hope this helps!

Attachments:
params_attribs.jpg (139.4 KB)

User Avatar
Member
767 posts
Joined: April 2014
Offline
Christopher R
You have to bind the Attribute VOP then you can call the Attribute within the POP Velocity but it must be binded, correct ?

What do you mean by "it must be binded? Are you referring to the Data Bindings tabs?
If you want to call Attributes within the POP Velocity.. the attribute should first exist.

I mean you have to create a attribute, followed by a VOP network within the attribute VOP, correct ?

As an alternative could you use a Wrangler (AttributeWrangler /PointWrangler) at SOP level and write out what's in VOP in the Wrangler then use that in the VEX POPVelocity ?

Yes, it is exactly what I did on the last sample file I uploaded (H15_velocity_vexpression.hiplc )
The attributes @myNoise and @myRamp were all created in SOPs level. Then POP Velocity was able to read those

I mean completely eliminating those Attribute VOPs and condensing everything from those Attribute VOPS into a wrangler node at SOP level ?
【T】【C】【S】
User Avatar
Member
252 posts
Joined:
Offline
I might still be missing something from what you said.. my apologies.
Christopher R
I mean you have to create a attribute,…
Yes, you have to create the attribute, via Wrangles/VOPs/Attribute Create/etc…
Christopher R
followed by a VOP network within the attribute VOP, correct ?
An Attribute VOP cannot have a VOP Network inside it, unless you were referring to subnets?


Christopher R
I mean completely eliminating those Attribute VOPs and condensing everything from those Attribute VOPS into a wrangler node at SOP level ?
Yes, all of those can be written inside a single Wrangle node at SOP level. It really just depends on the workflow
User Avatar
Member
767 posts
Joined: April 2014
Offline
Thanks for the info and help
Edited by _Christopher_ - Oct. 11, 2016 19:58:08
【T】【C】【S】
User Avatar
Member
73 posts
Joined: Dec. 2013
Offline
@galagast Thanks as well for the info!

Can I ask what is the best way to understand better VEX? I'm a no programmer guy trying to get that black magic in to my brain!
CG Generalist / FX Artist
http://www.jleandrovfx.com [www.jleandrovfx.com]
Jason Leandro.
User Avatar
Member
252 posts
Joined:
Offline
Hi Jason, I also started out as a non-programmer guy. You just have to continuously be open to using the language. Just enjoy learning it. I'm still learning new stuff myself
Best of luck!
  • Quick Links