脚本节点

    OSL was designed for node-based shading,and each OSL shader corresponds to one node in a node setup.To add an OSL shader, add a script node and link it to a text data-block or an external file.Input and output sockets will be created from the shader parameters onclicking the update button in the Node or the Text editor.

    OSL shaders can be linked to the node in a few different ways. With the Internal mode,a text data-block is used to store the OSL shader, and the OSO bytecode is stored in the node itself.This is useful for distributing a blend-file with everything packed into it.

    The External mode can be used to specify a file from a drive,and this will then be automatically compiled into a .oso file in the same directory.It is also possible to specify a path to a .oso file, which will then be used directly,with compilation done manually by the user. The third option is to specify just the module name,which will be looked up in the shader search path.

    • Linux
    • MS-Windows
    • macOS

    Tip

    For use in production, we suggest to use a node group to wrap shader script nodes,and link that into other blend-files.This makes it easier to make changes to the node afterwards as sockets are added or removed,without having to update the script nodes in all files.

    For more details on how to write shaders, see the.Here is a simple example:

    The available closures in Cycles correspond to the shader nodes and their sockets;for more details on what they do and the meaning of the parameters,see the shader nodes manual.

    • diffuse(N)
    • oren_nayar(N, roughness)
    • diffuse_ramp(N, colors[8])
    • phong_ramp(N, exponent, colors[8])
    • diffuse_toon(N, size, smooth)
    • glossy_toon(N, size, smooth)
    • translucent(N)
    • reflection(N)
    • refraction(N, ior)
    • transparent()
    • microfacet_ggx(N, roughness)
    • microfacet_ggx_aniso(N, T, ax, ay)
    • microfacet_ggx_refraction(N, roughness, ior)
    • microfacet_beckmann(N, roughness)
    • microfacet_beckmann_aniso(N, T, ax, ay)
    • ashikhmin_velvet(N, roughness)
    • hair_reflection(N, roughnessu, roughnessv, T, offset)
    • hair_transmission(N, roughnessu, roughnessv, T, offset)
    • principled_hair(N, absorption, roughness, radial_roughness, coat, offset, IOR)
    • bssrdf_cubic(N, radius, texture_blur, sharpness)
    • bssrdf_gaussian(N, radius, texture_blur)
    • henyey_greenstein(g)
    • absorption()
    • emission()
    • ambient_occlusion()
    • holdout()
    • background()

    Some object, particle and mesh attributes are available to the built-in getattribute() function.UV maps and vertex colors can be retrieved using their name.Other attributes are listed below:

    • geom:generated
    • Generated texture coordinates.
    • geom:uv
    • Default render UV map.
    • geom:dupli_generated
    • For instances, generated coordinate from duplicator object.
    • geom:dupli_uv
    • For instances, UV coordinate from duplicator object.
    • geom:trianglevertices
    • 3 vertex coordinates of the triangle.
    • Number of vertices in the polygon (always returns three currently).
    • geom:polyvertices
    • Vertex coordinates array of the polygon (always three vertices currently).
    • geom:name
    • Name of the object.
    • geom:is_curve
    • geom:curve_intercept
    • Point along the strand, from root to tip.
    • geom:curve_thickness
    • Thickness of the strand.
    • geom:curve_tangent_normal
    • Tangent Normal of the strand.
    • path:ray_length
    • Ray distance since last hit.
    • object:location
    • Object location.
    • object:index
    • Object index number.
    • object:random
    • Per object random number generated from object index and name.
    • material:index
    • Material index number.
    • particle:index
    • Particle instance number.
    • particle:age
    • Particle age in frames.
    • particle:lifetime
    • Total lifespan of particle in frames.
    • particle:location
    • Location of the particle.
    • particle:size
    • Size of the particle.
    • particle:velocity
    • Velocity of the particle.
    • particle:angular_velocity
    • Angular velocity of the particle.

    We support the function, to trace rays from the OSL shader.The "shade" parameter is not supported currently,but attributes can be retrieved from the object that was hit using the getmessage("trace", ..) function.See the OSL specification for details on how to use this.