Hydra: Noise
I mentioned the Hydra limitations before - especially if you aim for the use of your filters in Flash there are a lot of them. One feature that is entirely missing for example is a random number generator in form of a rnd() function. This wouldn't be such a bad thing, if there were at least some binary operators available. Since with the help of a little bitshifting, xor and bitmasking you can build your own random number generator pretty easily - here is a typical C# example:
function Noise(int x, int y)
{
int n = x + y * 57;
n = (n<<13) ^ n;
return ( 1.0 - ( (n * (n * n * r1 + r2) + r3) & 0x7fffffff) / 1073741824.0);
}
Well, it looks like we don't have that in Hydra (yet). Still there is an alternative. By using some nested sine functions with very high frequencies we can get something that looks pretty much like noise:

I admit that this doesn't look too exciting, but I think that there are quite a few things that can be created based on that. So here's the source: sineNoise.hydra
Posted at October 04, 2007 01:42 PM | Further reading
Just use parameters. Filters should always produce predictable results. You can provide random parameter at higher level. In ex. PerlinNoise::randomSeed parameter.
But how do you want to provide a random number for every single pixel? And BTW this function actually will produce a predictable result since it is purely mathematical.
The problem is, that it is supposed to be performed on the GPU. But there is no standard in bit-based operations in the GPU industry. Non of the major shader languages, such as GLSL or HLSL support bitwise operations.
It's really sad. It would give sooo many more opportunities.
Did i miss something? What are r1, r2 and r3 supposed to be? I would be very interessted in using this function.
With Shader Model 4 you can actually use bitwise operations on the GPU. Both HLSL (D3D10) and GLSL (EXT_GPU_shader4) can do this, but only on Geforce 8 and up.
Jan.
r1, r2 and r3 are three constants. In the real sourcecode they are f1, f2 and f3. But that sourcecode is also a bit outdated since it's from an early version of Hydra and will need to be adapted to the new Pixel Bender specifications.
Could you post the three constants here? I am not using Hydra, i only found this page, when i was looking for a noise function.
Thanks,
Jan.