15.3. Trade-offs
As previously mentioned, three methods can be used to generate noise values in a shader. How do you know which is the best choice for your application? A lot depends on the underlying implementation, but generally speaking, if we assume a hardware computation of noise that does not use texturing, the points favoring usage of the OpenGL Shading Language built-in noise function are the following.
It doesn't consume any texture memory (a 128 x 128 x 128 texture map stored as RGBA with 8 bits per component uses 8MB of texture memory). It doesn't use a texture unit (texture units are a scarce resource if the hardware supports only 2 or 4 of them). It is a continuous function rather than a discrete one, so it does not look "pixelated" no matter what the scaling is. The repeatability of the function should be undetectable, especially for 2D and 3D noise (but it depends on the hardware implementation). Shaders written with the built-in noise function don't depend on the application to set up appropriate textures.
The advantages of using a texture map to implement the noise function are as follows.
Because the noise function is computed by the application, the application has total control of this function and can ensure matching behavior on every hardware platform. You can store four noise values (i.e., one each for the R, G, B, and A values of the texture) at each texture location. This lets you precompute four octaves of noise, for instance, and retrieve all four values with a single texture access. Accessing a texture map may be faster than calling the built-in noise function.
User-defined functions can implement noise functions that provide a different appearance from that of the built-in noise function. A user-defined function can also provide matching behavior on every platform, whereas the built-in noise function cannot (at least not until all graphics hardware developers support the noise function in exactly the same way.) But hardware developers will optimize the built-in noise function, perhaps accelerating it with special hardware, so it is apt to be faster than user-defined noise functions.
In the long run, using the built-in noise function or user-defined noise functions will be the way to go for most applications. This will result in noise that doesn't show a repetitive pattern, has greater numerical precision, and doesn't use up any texture resources. Applications that want full control over the noise function and can live within the constraints of a fixed-size noise function can be successful using textures for their noise. With current generation hardware, noise textures may also provide better performance and require fewer instructions in the shader.
|