pld Posted November 14, 2006 Share Posted November 14, 2006 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) Where I'm I going wrong?? Thanks! Quote Link to comment Share on other sites More sharing options...
AndrewVK Posted November 14, 2006 Share Posted November 14, 2006 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). Any attribute exported with help of "maatrib" function becomes premultiplied with local density at current point. Quote Link to comment Share on other sites More sharing options...
pld Posted November 14, 2006 Author Share Posted November 14, 2006 Thanks AndrewVK, so are you saying that I should divide the radius by the density? I tried it and it doens't give the right effect... Quote Link to comment Share on other sites More sharing options...
AndrewVK Posted November 14, 2006 Share Posted November 14, 2006 Can U post your test scene here??? Quote Link to comment Share on other sites More sharing options...
pld Posted November 14, 2006 Author Share Posted November 14, 2006 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 Quote Link to comment Share on other sites More sharing options...
AndrewVK Posted November 15, 2006 Share Posted November 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
AndrewVK Posted November 15, 2006 Share Posted November 15, 2006 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); Quote Link to comment Share on other sites More sharing options...
pld Posted November 15, 2006 Author Share Posted November 15, 2006 Thanks for your help...think it's working now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.