Jump to content
Sign in to follow this  
JoshJ

hdk: first steps with UT_PNoise::noise3D

Recommended Posts

Hi,

 

So I'm making my first steps into the HDK, having very minimal, casual c++ experience over the years.  I successfully compiled some of the examples, and I'm experimenting with changing the demoVolumeSphere into a custom VRAY volume procedural.

 

It's going well, except I can't figure out how to get any 3d noise working.  I'm currently adjusting the vray_VolumeSphere::evaluate function.  Here's my current code:

 

included at the top is:

 

#include <UT/UT_PNoise.h>

---------------------------------------------

 

void
vray_VolumeSphere::evaluate(const UT_Vector3 &pos,
              const UT_Filter &,
              float, float,
              int idx, float *data) const

{

data[0] = -pos[1]+1 + UT_PNoise::noise1D(pos[0]);

}

 

---------------------------------------------

Correctly results in a 1d noise along the x axis.

 

However, as soon as I attempt to use any of the 3d noise, I can't get the types, pointers, and references to cooperate.

 

for example, when I use UT_PNoise::noise3D , I've tried every combination of * , &, etc I can think of for the inputs, but I always get an error message like:

 

error: no matching function for call to ‘UT_PNoise::noise3D(UT_Vector3&, const UT_Vector3&, int)’
     UT_PNoise::noise3D(dest,pos,1);

 

I know I haven't mastered a lot of the c++ pointer concepts, but I'd like to learn by example and figuring it out, and I'll eventually get it.  I looked through most of the HDK documentation though, and didn't find any example which could apply to this case.

 

If someone could write out a simple example for UT_PNoise::noise3D with const UT_Vector3 &pos as an input, resulting in a 1d value, that would be awesome.

Share this post


Link to post
Share on other sites

float x[3] = { pos(0), pos(1), pos(2) };

data[0] = UT_PNoise::noise3D(x);

  • Like 1

Share this post


Link to post
Share on other sites

Awesome, Thanks edward, it worked.

 

Now I'm experimenting with UT_Noise::turbulence , which doesn't have the float x[3] input.  Instead it has , for example:

 

  fpreal turbulence(

const UT_Vector3 &pos,
unsigned fractalDepth,
fpreal rough = 0.5,
fpreal atten = 1.0) const;
 
I'm not sure what to put for the "const" entry after the end parenthesis.
 
I've attempted to call it like this:
    const a = 0;
    fpreal x = UT_Noise::turbulence(pos,5) a;
    data[0] = -pos[1]+0.5 + x;
 
which of course did not work,
and I've tried a few variations and google searches about "error: cannot call member function ... const’ without object"
So, what does it mean when "const" is after the function parenthesis, and how do I call this type of function correctly?
 
also, for the void style of the function:
 
void turbulence(
const UT_Vector3 &pos,
unsigned fractalDepth,
UT_Vector3 &noise,
fpreal rough = 0.5,
 fpreal atten = 1.0) const;
 
Would I just create a UT_Vector3 variable beforehand, and enter it in like:
 
UT_Vector3 dest;
UT_Noise::turbulence(pos,5,dest);
 
Then dest contains my noise as a UT_Vector3 object?

Share this post


Link to post
Share on other sites

 the "const" after the member function name is just indicating that the function call won't affect the object it's a member of.  You can safely ignore it in your case (ie. you don't have to pass anything in place of the 'const' keyword).

 

 -G

 

 

 

Awesome, Thanks edward, it worked.

 

Now I'm experimenting with UT_Noise::turbulence , which doesn't have the float x[3] input.  Instead it has , for example:

 

  fpreal turbulence(

const UT_Vector3 &pos,
unsigned fractalDepth,
fpreal rough = 0.5,
fpreal atten = 1.0) const;
 
I'm not sure what to put for the "const" entry after the end parenthesis.
 
I've attempted to call it like this:
    const a = 0;
    fpreal x = UT_Noise::turbulence(pos,5) a;
    data[0] = -pos[1]+0.5 + x;
 
which of course did not work,
and I've tried a few variations and google searches about "error: cannot call member function ... const’ without object"
So, what does it mean when "const" is after the function parenthesis, and how do I call this type of function correctly?
 
also, for the void style of the function:
 
void turbulence(
const UT_Vector3 &pos,
unsigned fractalDepth,
UT_Vector3 &noise,
fpreal rough = 0.5,
 fpreal atten = 1.0) const;
 
Would I just create a UT_Vector3 variable beforehand, and enter it in like:
 
UT_Vector3 dest;
UT_Noise::turbulence(pos,5,dest);
 
Then dest contains my noise as a UT_Vector3 object?

 

Share this post


Link to post
Share on other sites

thanks ranxerox, that helps.

I figured out that UT_Noise needs to be instanced as an object like this:

    UT_Noise anoise;
    data[0] = -pos[1]+0.5 + anoise.turbulence(pos,5,0.5,0.5);

 

Now it works.

Share this post


Link to post
Share on other sites

How do I use the enum values for the noise?

 

    UT_Vector3 x = {pos(0),0,pos(2)};
    UT_Noise anoise;

// set the noise type here to alligator using an enum, like:

// anoise.setType(UT_Noise::UT_NoiseType(ALLIGATOR));  // which gives the error: ‘ALLIGATOR’ was not declared in this scope

    data[0] = -pos[1]+0.5+ anoise.turbulence(x,3,0.5,0.5)*0.1;

 

Edit:

Ok, I solved it,

anoise.setType(UT_Noise::UT_NoiseType::ALLIGATOR);

Edited by JoshJ

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  

×