开放式着色语言 (OSL)

    要开启这块功能,在渲染设置的着色器系统中选择开放式着色语言。

    Note

    在Linux上,C/C++ 编译工具(通常实践来说是/usr/bin/cpp)必须要安装来编译OSL脚本。

    脚本节点。

    OSL着色器可以通过几种不同的方式连接到节点。使用内部模式,将使用文本数据块存储OSL着色器,而OSO字节码则存储在节点本身中。这对于分配一个包含所有内容的bl末端文件非常有用。

    外部 模式可用于从驱动器指定 文件,然后它将自动编译成在同一个目录下的 .osl 文件。也可以指定一条路径到 .osl 文件,然后将直接使用,由用户手工完成编译。第三个选项是指定模块名称,它将在着色器搜索路径中查找。

    着色器的搜索地址可以在OSL脚本内所指定的地址下找到,如下:

    • Linux
    • MS-Windows
    • macOS

    Tip

    要取得更多着色器写入相关的资料,请看 。这里有一个简单例子:

    OSL is different from, for example, RSL or GLSL, in that it does not have a light loop.There is no access to lights in the scene,and the material must be built from closures that are implemented in the renderer itself.This is more limited, but also makes it possible for the renderer to do optimizations andensure all shaders can be importance sampled.

    在cycles中可用的闭包对应于着色器节点和套接口;对他们所做的更多的细节和参数的意义更多详细信息,请参阅 着色器节点手册

    • 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_refraction(N, roughness, ior)
    • 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()

    一些物件,粒子和模型属性也可以在自带的 getattribute() 函数取得。 UV贴图和顶点颜色也可以通过他们的名字检索。其他属性如下:

    • geom:generated
    • 生成纹理坐标。
    • geom:uv
    • 默认渲染UV贴图。
    • geom:dupli_generated
    • 例如从其他物件生成坐标。
    • geom:dupli_uv
    • 例如其他物件UV坐标。
    • geom:trianglevertices
    • 三角形的3顶点坐标。
    • 多边形的顶点数(通常返回值是3)
    • geom:polyvertices
    • 多边形的顶点数(通常返回值是3)
    • geom:name
    • 物件名称。
    • 物件是否线状。
    • geom:curve_intercept
    • 沿着线形从头至尾。
    • geom:curve_thickness
    • 线的厚度。
    • geom:curve_tangent_normal
    • 线股的切向法线。
    • path:ray_length
    • 光线到达距离。
    • object:location
    • 物件位置。
    • object:index
    • 物件索引号。
    • object:random
    • 通过物件的索引和名称生成的每个对象随机数。
    • material:index
    • 材质索引号。
    • particle:index
    • 粒子实例数量。
    • particle:age
    • 粒子帧寿命。
    • particle:lifetime
    • 粒子在帧的总寿命。
    • particle:location
    • 粒子的位置。
    • particle:size
    • 粒子的大小。
    • particle:velocity
    • 粒子的速度。
    • particle:angular_velocity

    这个功能不能代替照明;其主要目的是使着色器能够“探测”附近的几何形状,例如,应用可以被几何形状阻挡的投影纹理,应用更多的“磨损”来暴露几何图形,或者使其他环境遮挡效果类似。