povray

POV-Ray: what does a function in a pigment statement do?


This pigment statement appears in a code I found on the web, where depth is a number:

pigment{
    function{(depth+1)/3} 
    color_map{[0 rgb <0,0,0>][1/3 rgb <0,0,1>][2/3 rgb <1,0,1>][1 rgb <1,1,1>]}
}

What does function{(depth+1)/3} do? As I understand, this is the constant function returning (depth+1)/3. What is the role of this function in the pigment statement?


Solution

  • Ok, I understand now. That's easy.

    If depth = 1, (depth+1)/3 = 2/3, so the color map returns the color corresponding to 2/3, that is, rgb<1,0,1>.

    If depth = 2, (depth+1)/3 = 1, so the color map returns rgb<1,1,1>.

    If depth = 0.5, (depth+1)/3 = 0.5, so the color map returns the color interpolated between rgb<0,0,1> (1/3) and rgb<1,0,1> (2/3).

    A color_map is a map, and the value of the function gives the "key" of this map.