8. Finish maps

8.1. Description

Ce patch permet de spécifier une fonction au lieu d'un float ou d'une couleur pour les paramètres finish d'une texture. Les paramètres du finish sont alors évalués à chaque point d'intersection, lors du rendu.

8.2. Syntaxe

Dans la partie finish d'une texture, au lieu d'un float ou d'une couleur on peut donner soit un identificateur de fonction, soit une déclaration de fonction. Attention il faut que la fonction retourne une valeur/une couleur qui corresponde au type du paramètre.

finish {
    [uv_mapping]
    ambient COLOR | VECTOR_FUNCTION_IDENT | VECTOR_FUNCTION
    diffuse Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
    brilliance Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
    phong Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
    phong_size Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
    specular Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
    roughness Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION (Cf. warning)
    reflection COLOR | VECTOR_FUNCTION_IDENT | VECTOR_FUNCTION
    reflection { 
      Color_Reflection_Min | VECTOR_FUNCTION_IDENT | VECTOR_FUNCTION
      ,
      Color_Reflection_Max | VECTOR_FUNCTION_IDENT | VECTOR_FUNCTION
      falloff FLOAT_FALLOFF | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
      exponent FLOAT_EXPONENT | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION (Cf. warning)
    }
    irid { 
      Irid_Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
      thickness Amount | FLOAT_FUNCTION_IDENT | FLOAT_FUNCTION
    }   
}

Si uv_mapping est spécifié dans le bloc finish, l'évaluation se fait après passage des coordonnées en u,v.

Warning :  Pour roughness et exponent il faut une fonction qui retourne 1/roughness et 1/exponent.

8.3. Exemples

image avec finish maps
Finish maps
#declare fct = function { pigment { checker color rgb 0 color rgb 1 scale .1 } }

sphere { ...
  finish {
    uv_mapping
    reflection fct
  }

cone { ...
  finish {
    diffuse function {y}
  }
}

8.4. Program

Look for #ifdef FINISH_MAPS_PATCH in sources

The patch adds 3 new members to the FINISH struct : a number which indicates the number of evaluations required, a boolean to know if we must use uv_mapping, and a pointer to an array of a structure with an offset (offset to the member of the finish struct to modify) and a FUNCTION_PTR. This array is filled during the parsing, and sorted by function (so that after, if the same function is used by more than one member of finish, it is only evaluated once).

Possible improvements/problems

  • No tests for several declaration of the same member of finish
  • The functions are evaluated at beginning of shader calculations while some of them will not be needed later (for example no need to compute specular if it appears that the object is in shadow)