shader TexturePickerNoise
[[
int rfm_nodeid = 13,
string rfm_classification = "rendernode/RenderMan/pattern",
string help = "Brief description goes here."
]]
(
    float s = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
    float t = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
    string tex1 = "" 
        [[
        string widget = "filename",
        string label = "Texture 1",
        ]],
    string tex2 = "" 
        [[
        string widget = "filename",
        string label = "Texture 2",
        ]],
    string tex3 = "" 
        [[
        string widget = "filename",
        string label = "Texture 3",
        ]],
    string tex4 = "" 
        [[
        string widget = "filename",
        string label = "Texture 4",
        ]],
    string tex5 = "" 
        [[
        string widget = "filename",
        string label = "Texture 5",
        ]],
    string tex6 = "" 
        [[
        string widget = "filename",
        string label = "Texture 6",
        ]],
    string tex7 = "" 
        [[
        string widget = "filename",
        string label = "Texture 7",
        ]],
    string tex8 = "" 
        [[
        string widget = "filename",
        string label = "Texture 8",
        ]],
    int invertTex = 1 
        [[
        string widget = "checkBox",
        ]],
    int linearize = 1
        [[
        string widget = "checkBox",
        ]],
    color missingTexColor = color(1,0,1),
    output color resultRGB = 0) 
{
resultRGB = missingTexColor;
string textures[8] = {tex1,tex2,tex3,tex4,tex5,tex6,tex7,tex8};
  
// Get the value of the objects id
float id;
if(getattribute("identifier:id", id)) {
    color c = cellnoise( point(id, id + 7.0, id + 13.0) );
    int index = int(c[0] * 8);
    if(index >= 0 && index <= 8) {
        string texname = textures[index];
        if(texname != "") {
            float tt = (invertTex) ? 1 - t : t;
            resultRGB = texture(texname, s, tt);
    
            // The linearization code is from Pixar's implementation of
            // pxrsRGBLinearize() found in PxrTextureShared.h
            if(linearize) {
                float r = resultRGB[0];
                float g = resultRGB[1];
                float b = resultRGB[2];
                
                r = (r < 0.04045) ? r * 0.07739938 : pow((r + 0.055) * 0.947867299, 2.4);
                g = (g < 0.04045) ? g * 0.07739938 : pow((g + 0.055) * 0.947867299, 2.4);
                b = (b < 0.04045) ? b * 0.07739938 : pow((b + 0.055) * 0.947867299, 2.4);
                resultRGB = color(r, g, b);
                }
            }
        }
    }
}