Jump to content

hdk: first steps with UT_PNoise::noise3D


JoshJ

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.

Link to comment
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?
Link to comment
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?

 

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