Jump to content

Wrangle vex question about noise()


mart1jn

Recommended Posts

Hello,

 

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;
Link to comment
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.

 

Cheers,

Shawn

  • Like 2
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.

Guest
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...