Відкрита Мова Відтінювання – Open Shading Language
Cycles Only
It is also possible to create your own nodes using Open Shading Language (OSL). These nodes will only work with the CPU and OptiX rendering backend.
Для вмикання цього увімкніть стяг Open Shading Language у властивостях рендера, що дасть її використання як системи відтінення.
Примітка
Some OSL features are not available when using the OptiX backend. Examples include:
Memory usage reductions offered by features like on-demand texture loading and mip-mapping are not available.
Texture lookups require OSL to be able to determine a constant image file path for each texture call.
Some noise functions are not available. Examples include Cell, Simplex, and Gabor.
The trace function is not functional. As a result of this, the Ambient Occlusion and Bevel nodes do not work.
Вузол «Скрипт» – Script Node
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 on clicking 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 .osl
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
$HOME/.config/blender/4.0/shaders/
- Windows
C:\Users\$user\AppData\Roaming\Blender Foundation\Blender\4.0\shaders\
- macOS
/Users/$USER/Library/Application Support/Blender/4.0/shaders/
Порада
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.
Написання Шейдерів – Writing Shaders
For more details on how to write shaders, see the OSL specification. Here is a simple example:
shader simple_material(
color Diffuse_Color = color(0.6, 0.8, 0.6),
float Noise_Factor = 0.5,
output closure color BSDF = diffuse(N))
{
color material_color = Diffuse_Color * mix(1.0, noise(P * 10.0), Noise_Factor);
BSDF = material_color * diffuse(N);
}
Замикання – Closures
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 and ensure all shaders can be importance sampled.
Доступні замикання – closures у Cycles відповідають вузлам шейдерів та їх роз’ємам; детальніше про те, що вони роблять та значення цих параметрів, дивіться shader nodes manual.
BSDF
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)
microfacet_beckmann_refraction(N, roughness, ior)
ashikhmin_shirley(N, T, ax, ay)
ashikhmin_velvet(N, roughness)
Hair – Волосся
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
bssrdf_cubic(N, radius, texture_blur, sharpness)
bssrdf_gaussian(N, radius, texture_blur)
Volume – Об’єм
henyey_greenstein(g)
absorption()
Інше – Other
emission()
ambient_occlusion()
holdout()
background()
Attributes – Атрибути
Geometry attributes can be read through the getattribute()
function.
This includes UV maps, color attributes and any attributes output from geometry nodes.
The following built-in attributes are available through getattribute()
as well.
geom:generated
Automatically generated texture coordinates, from undeformed mesh.
geom:uv
Стандартна розкладка UV для рендера.
geom:tangent
Default tangent vector along surface, in object space.
geom:undisplaced
Position before displacement, in object space.
geom:dupli_generated
For instances, generated coordinate from instancer object.
geom:dupli_uv
For instances, UV coordinate from instancer object.
geom:trianglevertices
Three vertex coordinates of the triangle.
geom:numpolyvertices
Кількість вершин полігона (завжди повертає три поточні).
geom:polyvertices
Масив координат вершин полігона (завжди поточно три вершини).
geom:name
Ім’я об’єкта.
geom:is_smooth
Is mesh face smooth or flat shaded.
geom:is_curve
Is object a curve or not.
geom:curve_intercept
0..1 coordinate for point along the curve, from root to tip.
geom:curve_thickness
Thickness of the curve in object space.
geom:curve_length
Length of the curve in object space.
geom:curve_tangent_normal
Нормаль Тангенса пасма.
geom:is_point
Is point in a point cloud or not.
geom:point_radius
Radius of point in point cloud.
geom:point_position
Center position of point in point cloud.
geom:point_random
Random number, different for every point in point cloud.
path:ray_length
Відстань променя з моменту останнього потрапляння.
object:random
Random number, different for every object instance.
object:index
Object unique instance index.
object:location
Локація об’єкта.
material:index
Material unique index number.
particle:index
Particle unique instance number.
particle:age
Вік частинки у кадрах.
particle:lifetime
Загальна тривалість життя частинки у кадрах.
particle:location
Локація частинки.
particle:size
Розмір частинки.
particle:velocity
Скорість частинки.
particle:angular_velocity
Кутова скорість частинки.
Простеження – Trace
CPU Only
We support the trace(point pos, vector dir, ...)
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.
Ця функція не може використовуватися замість освітлювання; головне її призначення дозволити шейдерам «пробувати» найближчу геометрію, наприклад, для застосування проектованої текстури, що може бути блокована геометрією, застосувати більше «зношення» до виставленої геометрії або зробити інші ефекти подібні на загороду оточення.
Metadata – Метадані
Metadata on parameters controls their display in the user interface. The following metadata is supported:
[[ string label = "My Label" ]]
Name of parameter in in the user interface
[[ string widget = "null" ]]
Hide parameter in the user interface.
[[ string widget = "boolean" ]]
and[[ string widget = "checkbox" ]]
Display integer parameter as a boolean checkbox.