October 04, 2007
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.

Posted by: maliboo on October 4, 2007 02:43 PM

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.

Posted by: Mario Klingemann on October 4, 2007 02:53 PM

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.

Posted by: sam7 on October 18, 2007 08:18 AM

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.


Posted by: Jan on September 20, 2008 01:09 PM

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.

Posted by: Mario Klingemann on September 20, 2008 04:00 PM

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.


Posted by: Jan on October 17, 2008 01:15 AM
Post a comment

Email Address:



Remember info?

Thank you!

Most Visited Entries
Sketches, Works & Source Code
In Love with
Powered by
Movable Type 2.661

© Copyright Mario Klingemann

Syndicate this site:
RSS 1.0 - RSS 2.0

Quasimondo @ flickr
Quasimondo @ LinkedIn
Quasimondo @ Twitter
Quasimondo @ Facebook
Quasimondo @ MySpace
Quasimondo is a Bright
Citizen of the TRansnational Republic
My other blog in german

My family name is written Klingemann,
not Klingelmann, Klingeman, Klingaman, Kingemann,
Kindermann, Killingaman, Klingman, Klingmann, Klingonman
Klingemman, Cleangerman, Klingerman or Kleangerman

profile for Quasimondo at Stack Overflow, Q&A for professional and enthusiast programmers