This summary of the Shading Language syntax is intended more for aiding comprehension than as an exact description of the language.
Shading Language source files consist of definitions:
definition: shader_definition function_definition shader_definition: shader_type identifier ([formals]) { statements } function_definition: [type] identifier ( [formals] ) { statements } shader_type: light surface volume displacement imager formals: formal_variable_definitions formals ; formal_variable_definitions formal_variable_definitions: [outputspec] typespec def_expressions variables: variable_definitions ; variables variable_definitions ; variable_definitions: [externspec] typespec def_expressions typespec: [detail] type def_expressions: def_expression def_expressions , def_expression def_expression: identifier [def_init] def_init: = expression type: float string color point vector normal matrix void detail: varying uniform outputspec: output externspec: extern
statements: statements statement
statement: variable_definitions ; function_definitions; assignexpression ; procedurecall ; return expression ; loop_modstmt ; if ( relation ) statement if ( relation ) statement else statement loop_control statement { statements }
loop_control: while ( relation ) for ( expression ; relation ; expression ) gather ( [expressionlist] ) gather ( [expressionlist] ) statement else solar ( [expressionlist] ) illuminate ( [expressionlist] ) illuminance ( [expressionlist] ) loop_modstmt: loop_mod [integer] loop_mod: break continue
The basic expressions are:
expressionlist: expression [, expressionlist]
expression: primary expression binop expression - expression relation ? expression : expression typecast expression primary: number stringconstant texture identifier identifier [arrayindex] procedurecall assignexpression triple sixteentuple ( expression ) ( expression , expression , expression )
arrayindex: [ expression ]
triple: ( expression, expression, expression )
sixteentuple: ( expression, expression, expression, expression, expression, expression, expression, expression, expression, expression, expression, expression, expression, expression, expression, expression )
typecast: float string color [spacetype] point [spacetype] vector [spacetype] normal [spacetype] matrix [spacetype]
spacetype: stringconstant relation: ( relation ) expression relop expression relation logop relation ! relation assignexpression: identifier asgnop expression identifier [arrayindex] asgnop expression procedurecall: identifier ( [proc_arguments] ) proc_arguments: expression proc_arguments , expression texture: texture_type(texture_filename [channel] [texture_arguments] ) texture_type: texture environment shadow texture_filename: expression channel: [ expression ] texture_arguments: , expression texture_arguments , expression
The primary-expression operators
( )
have highest priority and group left-to-right. The unary operators
- !
have priority below the primary operators but higher than any binary or relational operator and group right-to-left. Binary, relational, and logical operators all group left-to-right and have priority decreasing as indicated:
binop: . / * ^ + - relop: > >= < <= == != logop: && ||
The conditional operator groups right-to-left
? :
Assignment operators all have the same priority and all group right-to-left.
asgnop: = += -= *= /=
Logical expressions have the value 1 for true, 0 for false. As in C, a non-zero logical expression is deemed to be true. In general, logical expressions are only defined for scalar types. The exception is == and != which are defined for every type.
Shading Language compilers will respect ANSI C preprocessor directives including:
#define identifier token-string #define identifier ( identifier , ... , identifier ) token_string #undef identifier #include "filename" #include <filename> #if constant-expression #ifdef identifier #ifndef identifier #else #endif #line constant identifier #pragma token-string
The behavior of these preprocessor directives should be identical to that expected from an ANSI C compiler, and it is reasonable to assume that a Shading Language compiler may use whatever compliant ANSI C preprocessor is available on a system. It should, therefore, not be assumed that the preprocessor truly understands the semantics of the Shading Language. For example, simple constant floating-point or boolean expressions that can be evaluated at compile time may be used for constant-expression, but not expressions involving vectors of other types specific to the Shading Language.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Pixar. The information in this publication is furnished for informational use only, is subject to change without notice and should not be construed as a commitment by Pixar. Pixar assumes no responsibility or liability for any errors or inaccuracies that may appear in this publication.
Pixar Animation Studios
|