cellnoise()

The cellnoise() shader function divides space into integer numbered cells and assigns random numbers to each cell. The technique used to create the random numbers is a simple hash function of the integer component of each value cellnoise() is given. The hash function is used to combine the parameters to an index into a table of random numbers between 0 and 1. If cellnoise() is returning a value to a point, the first index is used to calculate second and third indices to create pseudo random numbers for the point's x, y, and z components.

An implementation of cellnoise() is given below, cellnoiseDSO.c, along with tools to set up the needed tables: tables.c.

To see that cellnoise() is in fact a simple hashing function into a table of random numbers, one can actually use a shader to get a renderer to reveal the table of random numbers it uses. The shader would use a simple for loop to call cellnoise() enough times that the random numbers start repeating. By printing out the numbers, sorting and filtering out the unique numbers you see all the numbers that the renderer's table contains.

Random Number Tables Used in cellnoise()

Given a RIB file, such as test.rib, which is set to have 1 sample per pixel, a resolution of 1x1 and only one piece of geometry in camera view, the following surface shader code applied to the geometry will print out data that can be piped to sort using the commands 'rendrib test.rib | sort -u > BMRTUniqueNumbers' or 'prman test.rib | sort -u > PRManUniqueNumbers':

   for (i=-10; i<10; i+=1 )
   {
      for (j=-10; j<10; j+=1 )	
      {
         for (k=-10; k<10; k+=1 )
         {
            for (y=-10; y<10; y+=1 )
            {
	           p = cellnoise( point(i,j,k),y );
	           printf("%1.10f\n", xcomp(p));
	           printf("%1.10f\n", ycomp(p));
	           printf("%1.10f\n", zcomp(p));
            }
         }
      }
   }
You can try the other forms of cellnoise, but regardless of the number and ways you call cellnoise() the UniqueNumbers file mentioned above will have 2048 unique numbers for BMRT and 4096 unique numbers for PRMan.

These values are the random numbers used by the renderers in their cellnoise functions. Their cellnoise functions are calculating a hash function into a table of random values.

Creating Your Own Random Number and Permutation Tables

A program called random.c prints out a table of 2048 random numbers. The indexing into this table requires a hash function that will nicely distribute its accessing over an even spectrum of the random values. Using a table containing a permutation of all integers from 0 to 2047 creates a simple and efficient hash function. A program included here called permute.c sets up such a table of indices.

Creating Your Own cellnoise()

A shared object can be created that implements all of the cellnoise() parameter typed forms. Provided here is DSO code called cellnoiseDSO.c that implements the type of cellnoise described above using permutated indices and random numbers in tables.c.

Download

Two files are needed to build cellnoiseDSO.so:

cellnoiseDSO.c
tables.c

Two other programs were used to create the data in tables.c:

permute.c
random.c





[Affine Toolkit]
[RIB Utilities] [Bitmap Utilities] [Handy Little Utilities]
[Libraries] [Using the Libraries]