Jump to content
Sign in to follow this  

Wrangle vex question about noise()

Recommended Posts



I'm still new to houdini so please bear with me.

I have a question about the function noise(). In the help it states that the function can return a float or a vector.

In the following example the noise function seems to return a vector with 3 the same values. I would like to get 3 different values.

I could make 3 seperate values with a different seed and combine them, but I'm pretty sure that's not the best way. What can I do?

vector distort = {0,0,0};
float seed = 0.0;

seed = @ptnum*12.23 + @Frame * ch("speed");
distort = (noise(seed) - 0.5) * ch("scale");
@P += distort;

// these are for troubleshooting:
f@seed1 = seed;
v@distort1 = distort;

Share this post

Link to post
Share on other sites

Houdini has to decide which function to call. It's looking at these two function signatures:

float  noise(float)
vector noise(float)

And it has to pick one. The parameter in both is a float, so that doesn't help distinguish between the two. Houdini next looks at the return values. Do any of those possible return values make sense with the next operation? Your expression is:

(noise(seed) - 0.5)

And Houdini sees that you subtract a float, thus you must want a float back. Houdini chooses:

float  noise(float)

That value then gets multiplied by a float, your "speed" parameter, then the float is assigned to the vector distort. When a float is assigned to vector, the behaviour is to set each component to the same value. It's an implicit cast. That's what you noticed. The solution is to explicitly tell Houdini you want a vector back, even though you're about to subtract a float from the result. The full line becomes:

distort = (vector(noise(seed)) - 0.5) * ch("scale");

This is function casting. It's not a full cast from one variable type to another, so it's fast.




  • Like 2

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this