Sunday, February 01, 2009

Staying home the weekend

VOP AA Noise vs my custom noise


Parts of Australia have been enduring a severe heatwave this last week, and I kinda cancelled all weekend trail exploration plans, but found Sunday's weather to be quite tolerable. Perhaps next Sunday will be just as good?

Anyways, I'm writing a volume shader in VEX (mainly because I'm horrible at manipulating vops when loops are involved...) and wanted a VOP style AA Noise, so I implemented the code for fBm and MultiFractals, but was not pleased with the final look of the noise. I'm pretty certain its just me being too n00b.

I then decided I just wanted as close as possible the look of the noise generated by AA Noise, so this is what I came up with:

sop
gwMyNoise(float frequency=1, offset=0, freqMult = 2, roughness = 0.6, octaves = 4, amplitude = 1;)
{
float gwFreq = frequency;
float gwOffset = offset;
int i = 0;
float value = 0;

for (i=0; (float)i < octaves; i++)
{
if (i==0)
{
value += noise(P * gwFreq + gwOffset)-0.5;
}
else
{
value += (noise(P * gwFreq + gwOffset)-0.5 ) * pow(roughness, (float)i);
}
gwFreq = gwFreq * freqMult;
gwOffset = gwOffset * freqMult;
}

P.y = P.y + value*amplitude;

}


Basically, for the first generation of noise, i == 0, I will just take the base noise values. I subtract 0,5 because houdini's vex noise runs from 0-1. Once that is done, I will multiply the frequency and offset by freqMult, which is by default set to 2. Which means, multiply the noise for every generation by two. Thus for the 2nd generation, noise at twice the frequency is added to the previously generated noise.

However, the roughness parameter is included to modulate the noise every generation; the more generations the noise generated is, the lower its contribution. Of course, if roughness is set to 1, then pow(1, 9999) is still 1, adding the full noise value each generation. Not pretty....

Oh well, now that this test is done, I'm going to transform it into a vector version (ala for 3D space usage), and then proceed to use it in my volume shaders. The above code is for the SOPs context i.e. only for usage in Geometry, which I used to test it on similar geometry against the AA Noise VOP. The frequency multiplier is something I added in. Power to custom code =)

Alvin

No comments: