Jump to content

A simpe pscale VEX problem I can't solve


Recommended Posts

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.

Link to comment
Share on other sites

Hey Aaron,

I've done a simple SOP solver setup on just some basic spheres, but you can apply the same code to your setup if this is what you're looking for ^_^  

For the points to have some random pre-defined max sizes you can create an array of floats (the random sizes you wish to have), then create a random integer variable (between 0 & the length of the array) for each point to be used as the index of that array. Then all you have to do is to change the max parameter of the clamp() to be that. Meaning each points will have a random max size taken from the array.

Hope this helps! 





  • Like 2
Link to comment
Share on other sites

This is a glorious set up. I love it. To add some "Art Direction" to your existing setup is there a way to set up ratios to the randomness? Like could I have 60% small particles 20% to the medium particles 15% of the medium large particles and 5% large particles? Or some kind of simular way to sort of control the amount of each size?

Link to comment
Share on other sites

I think this little setup is so awesome and it's such a common thing in these little simulation and pretty instagram renders. I'm wondering with your permission I can post the setup to the "Houdini Blueprints" website. Or if you want to do it yourself for all the credit and prestige. I think it would help a lot of people.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...