In Houdini, VEX is commonly used in various contexts such as with geometry in SOPs, particles in POPs, or shading in SHOPs. To manipulate the size of particles randomly using VEX, you'll typically do this in a POP network (Particle Operators) where particles are being simulated.
Here’s a simple way to assign a random size to particles using a VEX expression in a POP network:
Create a Particle System: Start by creating a particle emitter. This can be done by using the Particle Emitter shelf tool or by manually creating a Geometry node and using a POP Network inside it.
Add a POP VOP or Attribute Wrangle node: Inside the popnet, add a POP VOP or a POP Wrangle node, which enables you to write custom VEX code to affect particle attributes.
Writing VEX Code:
If you are using a POP Wrangle, use the following VEX code to set the pscale attribute (which controls the size of the particles) to a random value:
In the above code, rand() generates a random number between 0 and 1. @ptnum is the unique identifier for each particle. By adding a seed (which you can control from a parameter), you can ensure different random results if needed. The scaleMultiplier channel allows you to control the maximum size of the particles.
To add the custom parameters (seed and scaleMultiplier), use the Parameter interface to add these channels right above the VEX code editor in the parameter editor of the node.
Adjust Parameters: Once your code is set up, you can adjust seed and scaleMultiplier parameters to get the desired randomness and size variation in your particles.
Simulate and Render: After setting up your particle system, simulate and render it to see the random sizes in action.
Here’s the step-by-step for the POP VOP:
Inside the popnet, add a POP VOP.
Drag and drop a Parameter VOP inside your VOP network to create user-defined parameters or directly use a Random node combined with a Multiply node to control the scale.
Connect the output of your size manipulation VOPs to the pscale attribute (typically you have to bind export pscale).
This approach will assign a random size to each particle at birth. If you wish to animate or change sizes over lifespan or any other attribute, you would need to incorporate those factors into your VEX code or node setup. Remember, in complex simulations, performance can vary based on the number of particles and complexity of your VEX code or node setup.