This module can be used to extract the parameters of a RenderMan shader either from the shader source file or from the compiled shader. To read parameters from a compiled shader it is necessary that the renderer package is installed that was used to compile the shader. Currently, the following renderers are supported:
Other renderers can be added at runtime (see the sloargs module).
Extracts the shader parameters from a RenderMan Shader file.
The argument slfile is either the name of a compiled shader, the name of the shader source file (*.sl) or a file-like object that provides the shader sources.
cpp determines how the shader source is preprocessed. It can either be a string containing the name of an external preprocessor tool (such as cpp) that must take the file name as parameter and dump the preprocessed output to stdout or it can be a callable that takes slfile and cpperrstream as input and returns the preprocessed sources as a string. If the external preprocessor does not produce any data a PreprocessorNotFound exception is thrown. The error stream of the preprocessor is written to the object specified by cpperrstream which must have a write() method. If cpperrstream is None, the error stream is ignored.
If cpp is None a simple internal preprocessor based on the simplecpp module is used. The slname argument is an alias for slfile, it is only available for backwards compatibility.
includedirs is a list of strings that contain directories where to look for include files. defines is a list of tuples (name, value) that specify the predefined symbols to use.
The function returns a list of shader info objects. These objects have four attributes:
The parameters are given as a list of shader parameter objects describing each parameter. A shader parameter object has the following attributes:
For backwards compatibility, the shader info object behaves like a 3-tuple (type, name, params). The meta data can only be accessed via name though. The shader parameter objects can also be used like 7-tuples containing the above data (in the order given above).
Example (output slightly reformatted for better readability):
>>> from cgkit import slparams
>>> shaders = lparams.slparams("plastic.sl")
>>> print shaders
[('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')])]
>>> shaders[0].type
'surface'
>>> shaders[0].name
'plastic'
>>> for param in shaders[0].params: print param.name
...
Ka
Kd
Ks
roughness
specularcolor
>>> shaders[0].meta
{}
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.
paramtuple must be a 7-tuple (or parameter object) 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:
SL type Python type float float string string color vec3 point vec3 vector vec3 normal vec3 matrix mat4
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.