Вузли Шейдерів – Shader Nodes#

Cycles applies a number of shader node optimizations both at compile time and run-time. By exploiting them it is possible to design complicated «Uber Shader» style node groups that incur minimal render time overhead for unused features.

Оптимізації Вузлів – Node Optimizations#

Першим кроком у підготовці вузла шейдера для виконання Cycles розгортає усі групи вузлів, ніби використовуючи засіб Розгрупування, та відкидає інтерфейс лиш таких функцій, як кадри та розводки вузлів.

After that, it applies some obvious transformations, for example, it can (the list is not exhaustive):

  • Замінити наступні вузли з результатом без змін їх оцінення, якщо всі їх уводи визначені без змін:

    RGB, Value, Mix RGB, Math, Vector Math, RGB to BW, Gamma, Bright Contrast, Invert, Separate/Combine RGB/XYZ/HSV, Blackbody, RGB Curves, Vector Curves, Color Ramps.

  • Виявити вузли Mix RGB, Math та Vector Math, що стають без операції (без Clamp) або обчислюються як 0 у результаті додання, віднімання, множення ділення або добутку векторів/скалярів з відомим уводом 0 або 1 без змін, та замінити відповідним увідним зв’язком або постійним результатом.

  • Усунути вузли Mix RGB Mix (без Clamp) та Mix Shader, коли Factor є відомо 0 або 1, замінивши відповідним увідним значенням або зв’язком.

  • Усунути незадіяні вузли Mix RGB (за винятком Color Burn, Color Dodge, Lighten, або з увімкненим Clamp), Invert, RGB Curves та Vector Curves з відомим нульовим Factor.

  • Усунути вузли шейдерів Emission та Background, щоб не емітують жодного світла, та вузли Add Shader з відсутніми одним чи обома аргументами уводів.

  • Eliminate Bump with constant Height input, using its Normal input or Geometry Normal instead. This is useful for implementing node group inputs that default to normal via routing through a no-op Bump before doing math.

  • Replace Attribute nodes of the View Layer type with the evaluated attribute value (it is constant within the whole Render Layer).

  • Скомбінувати кілька копій одного і того ж вузла з однаковими уводами в єдиний примірник.

Наостанок, будь-які вузли, що у кінцевому підсумку не з’єднані безпосередньо або опосередковано з вузлом виводу Output, вилучаються.

Оптимізації Під час виконання – Run-Time Optimizations#

When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.

This can substantially reduce the performance cost of combining multiple materials in one shader with a Color Attribute, texture, or other input used as a switch.

Відкрита Мова Відтінювання – Open Shading Language#

If Open Shading Language is chosen as the rendering backend, node shaders are translated to OSL code and then compiled and executed by the OSL runtime. In the process it applies its own extensive set of optimizations, both at compile time and run-time.

Open Shading Language can optimize out Script nodes if their outputs are unused or constant, even if their OSL shaders have side effects like debug tracing and message passing, which may be confusing. For that reason message passing with setmessage and getmessage should generally not be used for passing information forward in the graph; explicitly passing information through sockets should be preferred.