slparams -- Extracting RenderMan Shader parameters

New in version 1.1. This module can be used to extract the parameters of a RenderMan shader from the shader source file.
slparams(slname [, cpp[, cpperrstream]])
Extracts the shader parameters from a Shading Language source file.

The argument slname is the name of the shader source file (*.sl). cpp is the name of the preprocessor to use (default = "cpp") which has to be installed on the system. If the preprocessor doesn't produce any data a PreprocessorNotFound exception is thrown. If cpp is None, then the input file is parsed directly. The error stream of the preprocessor is written to the object that's specified by cpperrstream which must have a write() method (default = sys.stderr). If cpperrstream is None, the error stream is ignored.

The function returns a list of 3-tuples, one for each shader found in the file. The tuple contains the type, the name and the parameters of the shader. The parameters are given as a list of 7-tuples describing each parameter. The tuple contains the following information (in the given order):

  1. The output specifier (either "output" or an empty string)
  2. The storage class ("uniform" or "varying")
  3. The parameter type
  4. The array length or None if the parameter is not an array
  5. The name of the parameter
  6. The space in which a point-like type or a color was defined. If the parameter is an array then this is also an array of space names.
  7. The default value (always given as a string)

Example (output slightly reformatted for better readability):

  >>> import slparams
  >>> slparams.slparams("")
  [('surface', 'plastic', 
    [('', 'uniform', 'float', None, 'Ka', None, '1'),
     ('', 'uniform', 'float', None, 'Kd', None, '0.5'),
     ('', 'uniform', 'float', None, 'Ks', None, '0.5'),
     ('', 'uniform', 'float', None, 'roughness', None, '0.1'),
     ('', 'uniform', 'color', None, 'specularcolor', 'rgb', '1')])]

The parser used inside this function was generated using the parser generator Yapps by Amit Patel.

Converts the default value of a shader parameter into a Python type. The argument paramtuple must be a 7-tuple as returned by slparams(). The function returns a Python object that corresponds to the default value of the parameter. If the default value can't be converted then None is returned. Only the functions that are present in the sl module are evaluated. If a default value calls a user defined function then None is returned. The SL types will be converted into the following Python types: Arrays will be converted into lists of the corresponding type.
The module defines the following exception classes:
Base class for the exceptions in this module. This class is derived from the Exception class.
This exception is thrown when calling the preprocessor didn't produce any data.
This exception is thrown when a syntax error is found in any function or shader definition. The exception has the following attributes:
This exception is thrown when the parser runs out of tokens.

Copyright © 2004 Matthias Baas (

The RenderMan (R) Interface Procedures and Protocol are:
Copyright 1988, 1989, 2000, Pixar
All Rights Reserved

RenderMan (R) is a registered trademark of Pixar