AEJoy —— AE 插件开发中的 SmartFX (一)

654 阅读2分钟

「这是我参与11月更文挑战的第 13 天,活动详情查看:2021最后一次更文挑战」。

参加该活动的第 28 篇文章

正文

SmartFX

SmartFX API 提供了 effects 和 After Effects 之间的双向通信,实现了许多性能优化,并提供了以前不可用的依赖信息。这个 effect API 的扩展是实现 After Effects 中支持每个通道 32 位的方法。

普通 effect 插件提供了一个全尺寸输入缓冲区,并要求渲染一个全尺寸输出缓冲区。虽然输出 extent_hint 指定了实际上需要填充的输出缓冲区的部分,但如果该效果并不需要整体输入,那么这个方案仍然非常低效。而且,许多效果并不使用范围提示(extent hints)。

SmartFX

The SmartFX API provides bidirectional communication between effects and After Effects, enabling many performance optimizations and providing previously unavailable dependency information. This extension of the effect API is the way to implement 32-bit per channel support in After Effects.

Normal effect plug-ins are given a full-sized input buffer, and asked to render a full-sized output buffer. While output extent_hint specifies the portion of the output buffer that must actually be filled, this scheme is still very inefficient if the effect does not need its entire input. Also, many effects don’t use extent hints.

前世

比如,考虑将模糊效果应用到一个很大的层上,这个层大部分是在屏幕外(离屏)的,或者是通过一个小的感兴趣的区域进行观察,或者蒙版到一个小的尺寸上。这些情况对使用了输出 extent_hint 的效果来说,都只需要渲染输出一小部分。同样,需要被模糊的输入也只有一小部分 —— 输出的 extent_hint会根据模糊半径进行扩展 。然而,使用遗留(过时) 的 effect API, After Effects 就没有办法知道这一点,因此整个层会被传递给插件。这些额外的像素在计算上非常昂贵和浪费,特别是在之前有多个效果或嵌套合成的情况下。

The Way Things Were

Consider a blur effect applied to a huge layer which is mostly off-screen, or viewed through a small region of interest, or masked down to a small size. Only a small section of the output needs to be rendered, indicated to the effect using the output extent_hint. Only a small section of the input to be blurred is needed as well - the output extent_hint expanded by the blur radius. However, using the legacy effects API, there is no way for After Effects to know this, so the entire layer is passed to the plug-in. These extra pixels can be extremely expensive and wasteful to compute, especially in the case of prior effects or nested comps.