OSL Support

OSL Support Overview

OSL shaders describe the appearance of a surface using symbolic representations called closures instead of explicitly computing color values. V-Ray supports some of the closures introduced by the OSL specification. Additionally V-Ray customizes the usage of OSL closure functions by defining keyword arguments. These arguments reveal additional parameters to better configure V-Ray BRDFs working behind the scenes of the OSL closures. Currently there are several guidelines and limitations to writing an OSL shader in V-Ray. See the Examples section for some samples.

Guidelines

There are several guidelines and limitations to writing an OSL shader in V-Ray:

    • Only surface shaders are supported.

    • VRayOSLTex plugin ignores closure color output. Writing to built-in closure output variable Ci is redundant. Use only simple color output results for texture shaders.

    • There are two types of non-closure output variables supported. For simple color results use an output color variable named "result". As for opacity use either output color transparency (for material description) or output float alpha (for texture description).

      Texture shader example:

    surface simple_color_tex

    (

    color tex_color = color (0.2, 0.45, 0.9),

    output color result = color (0.0, 0.0, 0.0),

    output float alpha = 1.0

    )

    {

    result = tex_color;

    alpha = 1.0;

    }

    Material shader example:

    surface diffuse_material

    (

    color diffuse_color = color (0.2, 0.45, 0.9),

    output color transparency = color (0.0, 0.0, 0.0)

    )

    {

    Ci = diffuse_color * diffuse ( N );

    transparency = color (0.0, 0.0, 0.0);

    }

    • Writing to built-in closure output variable Ci in a shader causes output color result to be ignored when loaded in VRayOSLMtl.

    NOTE: These features are available only for V-Ray Standalone and V-Ray for Max.

    NOTE: An OSL compiler that translates *.osl files to *.oso files can be found in the tools subdirectory of V-Ray's root installation folder.

    Supported OSL Closures

    Out of the many closure functions that OSL specifies VRay supports the following:
    closure color diffuse(normal N);
    closure color orennayar(normal N, float roughness);
    closure color phong(normal N, float exponent);
    closure color ward(normal N, vector T,float ax, float ay);
    closure color cooktorrance(normal N, float glossiness);
    closure color reflection(normal N, float eta);
    closure color refraction(normal N, float eta);

    Additionally we define:
    closure color blinn (normal N, float glossiness, float anisotropy, float anisoRotation);
    Closure that can be used to create Blinn highlight/reflections for a surface.

    closure color light (int doubleSided, int emitOnBackSide);
    Use the light closure function to convert simple color results to closure colors writable to Ci. This can be helpful when you are developing a simple material shader that has no closure output result but still it is necessary to use the material as an input to the VRayBlendMtl.

    Additional Closure Arguments

    The OSL closure functions allow for additional customization via keyword arguments. Listed below are the VRay specific keyword arguments for some of the supported closures.

    closure color diffuse(normal N);
    float roughness;

    Keyword usage example:
    Ci = diffuse_color * diffuse(N, "roughness", 0.5);

    closure color phong (normal N, float exponent);
    float reflection_glossiness;
    float soften_edge;
    int subdivs;
    int trace_reflections;

    closure color blinn (normal N, float glossiness, float anisotropy, float anisoRotation);
    float reflection_glossiness;
    float soften_edge;
    int subdivs;
    int trace_reflections;

    closure color ward (normal N, vector T, float ax, float ay);
    float highlight_glossiness;
    float anisotropy;
    float aniso_rotation;
    float reflection_glossiness;
    float soften_edge;
    int subdivs;
    int trace_reflections;

    closure color cooktorrance (normal N, float glossiness);
    float anisotropy;
    float aniso_rotation;
    float reflection_glossiness;
    float soften_edge;
    int subdivs;
    int trace_reflections;

    closure color refraction (normal N, float eta);
    float glossiness;
    int subdivs;

    Additional argument information:

    float roughness;
    Controls surface roughness. Ranges from 0 to 1. Use 0 for regular diffuse surface. Increase the value to achieve flat or dusty effect.

    float highlight_glossiness;
    Controls the shape of the highlight on the material. Ranges from 0 to 1. Larger values create more specular surface.

    float reflection_glossiness;
    Controls the sharpness of reflections. Ranges from 0 to 1. Use 1 for perfect mirror-like reflection.

    float anisotropy;
    Determines the shape of the highlight. Use this to simulate "brushed" surfaces. Ranges from -1 to 1 (exclusive). A value of 0.0 means isotropic highlights. Negative values stretch the highlight vertically while positive ones horizontally.

    float aniso_rotation;
    Determines the orientation of the anisotropic effect in degrees (rotation in degrees).

    float soften_edge;
    Softens the transition from dark to bright areas in specular reflections. Ranges from -1 to 1.

    int subdivs;
    Controls the noise quality of glossy surfaces. Larger number means less noise but longer render time.

    int trace_reflections;
    Use 1 to enable reflections or 0 to disable them.

    Notes

    Open Shading Language specification officially supported is 1.0.