// This shader demonstrates how to read a float attribute, for example,
//    Attribute "user" "float particle_id" [22]
//      or
//      Attribute "identifier" "float id" [22]
// The value of the attribute is used to generate an arbitrary color using the 
// cellnoise() function. The technique is based on the method used by Pixar's 
// PxrVisualizer integrator plugin.
// Malcolm Kesson
// 28 Sept 2017
shader
attrToColor
[[
int rfm_nodeid = 20,
string rfm_classification = "rendernode/RenderMan/pattern",
string help = "Brief description goes here."
]]
(
    string attrName = "user:particle_id" 
        [[
        string help = "another example 'identifier:id'",
        ]],
    color missingAttrColor = color(1,0,1) 
        [[
        string label = "Missing Attr Color",
        ]],
    float saturation = 1,
    output color resultRGB = 0)
{
float id;
if(getattribute(attrName, id)) {
    resultRGB = cellnoise( point(id, id + 7.0, id + 13.0) );
    color hsvColor = transformc("hsv", resultRGB);
    hsvColor[1] = hsvColor[1] * saturation;
    resultRGB = transformc("hsv", "rgb", hsvColor);
    }
else
    resultRGB = missingAttrColor;
}
RfM: CustomizingRfM: Customizing