This tutorial presents a two methods of applying 1 to 8
texture maps to multiple surfaces using a single material. Unlike the
technique outlined in the tutorial,
Attribute "identifier" "float id" 
The value of the attribute is used by the two shaders shown below to choose a texture
that is read by the OSL
Method 1: Cycling Texture Maps
The result of using the first shader, TexturePickerCycle.osl,
on a grid of squares is shown in figure 1. The UI of the shader is shown in figure 2.
The shader uses simple arithmetic to calculate a value that is used to index into an array of texture paths.
For example, suppose the shader is evaluating a surface with an identifier:id of
Calculating "index" in this way ensures it will have a value in the range 0 to 7. Setting "cycles" to, say, 7 results in a semi-random distribution of textures.
Method 2: Using Cellnoise to Choose Texture Maps
The result of using the second shader, TexturePickerNoise.osl,
on a grid of squares is shown in figure 4.
The shader uses a more computationally expensive technique to calculate a random value that is used to index into an array of texture paths. The use of OSL cellnoise() function is based on the method used by Pixar's PxrVisualizer plugin to produce random colors.
Because cellnoise() returns repeatable noisy color values we can use either the red, green
or blue component to generate an "index" value that is once again constrained to be in the
range 0 to 7.
© 2002- Malcolm Kesson. All rights reserved.