A simple pscale vex problem I cannot solve.

   3990   6   0
User Avatar
Member
12 posts
Joined: Jan. 2017
Offline
Being quite new to Houdini and VERY new and completely out of my depth in VEX I have a problem which should be simple for anyone who is smart. So the setup is I have some popgrains spawning on an object that scale from 0.001 up to 0.025 using some VEX and then having those grains stick to the surface of the context geometry. Using the following code...
@pscale += 0.001;
@pscale = clamp(@pscale, 0, 0.025)*1.5;
int pr;
vector uv;
float d = xyzdist(1,@P,pr,uv);
@P = primuv(1,'P',pr,uv);

This works fine and spawns particles that grow to all be a uniform size. My question is. What do I add or how do I change that code to add some randomness to the size that the grains scale up to. I have tried to wrap my head around the "rand" function inside the clamp function but ended up making everything explode into giant grains.

I KNOW there is a simple solution to this but not having the brain for code just yet out of pure ignorance I don't know what to do. Could anyone help possibly?

ALSO as a bonus for anyone who is super genius. Is there a way to define a determined number of sizes the pscale of grains can be? For example have 5 different sizes that a grain can be based on a seed or even better a probability so I can control how many of each sized grain could show up at spawn?

ALSO ALSO if you could help me with this, Can I use VEX to assign Cd values to each size clone to have the ability to have different materials on different grains based upon their size.

It seems like I'm asking a lot but I'm sure someone here is thinking "Pftt this is just 3 lines of code." And could help me work it out.
User Avatar
Member
339 posts
Joined: Nov. 2013
Offline
You can add randomness with the rand() function. It generates a number between zero and one. You can use the fit01() function to remap the random number it gives you to an appropriate range and add it to pscale.

To create "buckets" of scales and colors I would use a float and color ramp. The probability is then managed by the ranges in the ramp which gives a nice visual of what the result will be. Since a ramp lookup is from zero to one you can use the rand() function again to generate a random coordinate. The knot positions on the color ramp are connected by expressions to the knots on the sizes ramp so that the two stay in sync. If you add more knots you'll need to sync the new positions.

It's 3 lines of code if you don't include the comments hip file attached.

Image Not Found

Edited by antc - March 26, 2022 20:02:21

Attachments:
ramps.gif (1.1 MB)
rampss.hipnc (213.3 KB)

User Avatar
Member
12 posts
Joined: Jan. 2017
Offline
I freaking love this setup man. It pretty much hits all the birds with one stone except for one thing. I am wondering if we can add to this setup a way to have the particles start at 0 and scale up over a set time like 10 or 20 frames or something like that. Is it possible?
User Avatar
Member
339 posts
Joined: Nov. 2013
Offline
To have the grains scale up over some time interval try remapping the age attribute to the scale you want. The fit function takes a value, old range min/max and new range min/max. e.g

@pscale = fit(@age, 0, 2.0, 0, 0.05);

Would scale up from 0 to 0.05 over the first two seconds.
Edited by antc - March 27, 2022 10:59:49
User Avatar
Member
734 posts
Joined: Dec. 2006
Offline
You might also want to spend some time looking at the "attribute adjust integer/float/vector" sops that nicely wrap up almost all of these kinds of random and remapping assignments thingies I used to do in wrangles.
Sean Lewkiw
CG Supervisor
Machine FX - Cinesite MTL
User Avatar
Member
12 posts
Joined: Jan. 2017
Offline
Thanks so much for your help everyone. I definitely will look into all of this more and see if I can get my setup running simpler or have a more refined and elegant setup. It feels like I have learnt so much just from this one little project. Now I KNOW this might be pushing it. But would it also be possible to map the clones to values in some gradient noise or something to even further super art direct them? Or is that asking too much?
Edited by neutrosophic - March 28, 2022 11:18:06
User Avatar
Member
734 posts
Joined: Dec. 2006
Offline
neutrosophic
Thanks so much for your help everyone. I definitely will look into all of this more and see if I can get my setup running simpler or have a more refined and elegant setup. It feels like I have learnt so much just from this one little project. Now I KNOW this might be pushing it. But would it also be possible to map the clones to values in some gradient noise or something to even further super art direct them? Or is that asking too much?
Check out the attribute adjust float SOP, this is indeed one of its features. The help for this node is very good too: https://www.sidefx.com/docs/houdini/nodes/sop/attribadjustfloat.html [www.sidefx.com]

Attachments:
Selection_003.png (53.7 KB)

Sean Lewkiw
CG Supervisor
Machine FX - Cinesite MTL
  • Quick Links