Color Handling In OSL Shaders


Octane is a spectral renderer, so it handles the color variable type in a somewhat non-standard way.


Spectrum and RGB

Depending on what returned a given color value, a color variable may be represented internally as RGB or as a spectral color. When expressions use both RGB colors and spectral colors, the RGB colors will be converted to spectral colors.


“a” will be an RGB color:

color a = 1;

“b” will be an RGB color:

color b = {1, 0.5, 0};

“c” will be a spectral color:

color c = _gaussian(1, 0.5, 0.01);


Adding two RGB colors results in another RGB color:

color d = a + b


Note: Adding a spectral color to another color always results in a spectral color.


In practice, most colors will end up being represented as RGB colors. The main exceptions are blackbody and Gaussian spectra.


RGB colors support element access (using []) and casting to point-like types. For spectral colors this can be done only approximately, and the result will have poor color fidelity. The compiler will emit a warning if this happens.


To learn more about programming with the Open Shader LanguageA shading language developed by Sony Pictures Imageworks. There are multiple render engines that utilize OSL as it is particularly suited for physically-based renderers. refer to The Octane OSL Guide.