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

423 阅读2分钟

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

参加该活动的第 29 篇文章

正文

今生

SmartFX 通过反转调用序列来解决这个问题。effect 被告知需要多少输出,并且必须显式地向主机请求它需要的输入。渲染过程分为两部分:预渲染渲染

预渲染期间,effect 描述了它需要的输入像素数据;这个必要的输入可以根据您喜欢的任何内容而变化(比如,非输入层参数非层参数来自 in_data 的信息序列数据中的设置等……)。效果还必须返回结果输出的范围(extent),如果层请求的部分中有空像素,则该范围可能小于请求的大小。

渲染阶段,effect 只能检索它以前请求过的像素。这种双通道(Pass)的方法有助于许多重要的优化。例如,一个将一个输入另一个输入相乘或遮罩的效果可能会发现,如果遮罩没有和第一个输入相交,那么它的第一个输入就根本不需要。After Effects 内部还执行了一些重要的优化,以确保图像缓冲区的复制尽可能少,这些优化只有在主机知道缓冲区大小和所有输入输出之后才可能实现。

像 AEGP 一样,SmartFX 插件不会被 After Effects 卸载。

The Way Things Are Now

SmartFX solves this problem by reversing the calling sequence. The effect is told how much of its output is required, and must explicitly ask the host for the inputs it needs. The render process is split into two parts: pre-render and render.

During pre-render, the effect describes the input pixel data it needs; this necessary input can vary based on anything you like (non-input layer parameters, non-layer parameters, information from in_data, settings in sequence data…). The effect must also return the extent of the resulting output, which may be smaller than the requested size if there are empty pixels in the requested portion of the layer.

During the render stage, the effect can only retrieve pixels that it has previously requested. This two-pass approach facilitates many important optimizations. For example, an effect which multiplies or mattes one input against another might discover that its first input is not needed at all, if the mask does not intersect it. There are also important optimizations that are performed internally by After Effects to ensure that image buffers are copied as little as possible, and these optimizations are only possible after the host knows the buffer sizes and for all inputs and outputs.

Like AEGPs, SmartFX plug-ins are never unloaded by After Effects.