Jump to content

I3d Variable Frequency


pld

Recommended Posts

Hi All,

I'm writing a new i3d shader to store more data than just density...

I'm trying to vary the frequency parameter in the VEX meta cloud shader based on the size of the metaballs. Basically, I want to have the frequency to be proportional to the radius of metalballs.

I created a RAD attribute which stores the size of the metaball (the radius). I then read this parameter using mattrib. The result that I get is close but not entirely correct. This is the relevant part of the code..

forpoints(P)
		{
radius=mattrib("RAD",P);

//radius=1.0;
//printf("radius %f\n",radius);
scaled_freq=freq*radius;

}

I then compute the noise using scaled_freq....

If create a single metaball with size of 1.0, the radius variable should be 1.0. However if I print radius in the loop I can see values of 1.0, 0.0 and other numbers. The RAD attribute has the correct value (1.0). As you can see from the image (right) the edge seems cropped.

If on the other hand, I hardcode radius=1.0, the result is what I expect (left of image)

post-975-1163506799_thumb.jpg

Where I'm I going wrong??

Thanks!

Link to comment
Share on other sites

Here's a test scene with a simple i3d shader which is supposed to read the radius of the metaballs...

If you look at the test i3d shader you'll see an option to scale the frequency based on the scale of the metaball. Basically, this reads the radius of the metaball (using mattrib) and multiplies this value by the frequency.

Since (as a test) I have a metaball with 1.0 radius this option should do nothing. However, as you can see, if you click on it, the result is slightly different than simply having the per-point option on by it self. The error becomes more apparent as you increase the amplitude value.

Hope you can help!

cheers

noise.zip

Link to comment
Share on other sites

First of all forget about unpremultiply in this particular case...because You are using "forpoints" loop.

As doc (finally :)) says:

Note that when calling mattrib inside of a forpoints loop, the attribute is not pre-blended by the density of the metaball.

>>The error becomes more apparent as you increase the amplitude value.

Of course!!!

You have an metaball with radius = 1

And distort density field by noise with amplitude 1.5...greater then metaball radius.

This means that point with density = 1 might be shifted very close (or even beyond) to edge of i3d lattice.

Link to comment
Share on other sites

Also note that at some points of i3d lattice "radius" variable might be undefined.

Because there is no intersection between sphere (metaball) and box (i3d cage)

So...

scaled_freq=freq;
if(scaledfreq)
  {radius=mattrib("RAD",P);
  // scaled_freq=freq*radius; WRONG!!! because scaled frequency might be 0
  if (radius > 0) scaled_freq=freq*radius;
  }

// Convert to the space of the metaball.  Now, P is somewhere in
// the unit sphere.
pp = mspace(P);

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