Open Shading Language

· Programming language · Computer graphics · 3D · #note/sink ·


int Bob = 12;
float Jim = 15.0;
point Somewhere = point(1,2,4);
type array[4] = {x, y, z, q};
type array[] = {x, y, ... }

// Define a structure type
struct RGBA {    
	color rgb;
	float alpha;
// Declare a structure
RGBA col;
// Assign to one field     
r.rgb = color (1, 0, 0);
// Read from a structure field
color c = r.rgb;
// Member-by-member initialization
RGBA b = { color(.1,.2,.3), 1 };


returnType FunctionName(type name1, type name2...) { ... }
void FunctionName(...) { ... } // no return function
void FunctionName(..., output float X) { ... } // return to parameter

shader MyCustomShader(
		type Name1 = x,
		type Name2 = y,
		output type Name3 = z) { ... }


/* muliline */
// oneliner

Shader Types

surface, displacement, light, volume, shader

Global Variables

type var value
point P Position of the point you are shading. In a displacement shader, changing this variable displaces the surface.
vector I The incident ray direction, pointing from the viewing position to the shading position P.
normal N The surface “Shading” normal of the surface at P. Changing N yields bump mapping.
normal Ng The true surface normal at P. This can differ from N; N can be over-ridden in various ways including bump mapping and user-provided vertex normals, but Ng is always the true surface geometric normal of the surface at P.
float u, v The 2D parametric coordinates of P (on the particular geometric primitive you are shading).
vector dPdu, dPdv Partial derivatives ∂P/∂u and ∂P/∂v tangent to the surface at P.
point Ps Position at which the light is being queried (currently only used for light attenuation shaders)
float time Current shutter time for the point being shaded.
float dtime The amount of time covered by this shading sample.
vector dPdtime How the surface position P is moving per unit time.
closure color Ci Incident radiance — a closure representing the color of the light leaving the surface from P in the direction -I.


F value
M_PI π
M_PI_2 π/2
M_PI_4 π/4
M_2_PI 2/π
M_2_SQRTPI 2/√π
M_E e
M_LN2 ln 2
M_LN10 ln 10
M_LOG2E log2e
M_LOG10E log10e
M_SQRT2 √2
M_SQRT12 √1/2