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

430 阅读2分钟

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

参加该活动的第 34 篇文章

正文

Rectangles

effects 必须精确地设置两个结果矩形。After Effects 的缓存系统依赖于它们,不正确的值会导致许多问题。如果插件返回一个比 request_rect 小的 result_rect,这就告诉 After Effects 位于 request_rect 内但位于 result_rect 外的像素是空的。

类似地,max_result_rect 必须包含所有非零像素; 这个 effect 永远不会被要求渲染这个区域之外的任何东西。如果在这个矩形之外有像素,它们将永远不会显示。

输出矩形的大小不合适也会造成问题。如果这些矩形太大,就会导致性能的损失。

不仅会缓存许多空像素(占用了应用程序宝贵的内存),还可能不必要地要求渲染大面积的空区域。因此,必须正确地计算 max_result_rect,而不是将其设置为任意大的尺寸。

result_rectmax_result_rect 都可能根据 effect 的参数、当前时间等而变化; 它们仅对给定的 effect 调用有效。然而,max_result_rect 不能依赖于特定的渲染请求。无论 After Effects 请求 输出 的哪一部分,它都必须是相同的。

如果 request_rect 不与 effect 的输出像素相交,则返回一个空 result_rect 是合法的; 不需要渲染。

After Effects 也可以使用空的 request_rect 调用 effect ,这意味着 effect 只被要求计算 max_result_rect

preserve_rgb_of_zero_alpha 可以影响边界计算过程(包括 result_rectmax_result_rect),如果 effect 的不同表现取决于这个设置,则必须考虑preserve_rgb_of_zero_alpha

Rectangles

Effects must set both result rectangles accurately. After Effects’ caching system relies upon them, incorrect values can cause many problems. If the plug-in returns a result_rect smaller than the request_rect, that tells After Effects the pixels inside the request_rect but outside the result_rect are empty.

Similarly, max_result_rect must encompass all non-zero pixels; the effect will never be asked to render anything outside this region. If there are pixels outside this rectangle, they will never be displayed.

Mis-sized output rectangles can cause problems as well. If these rectangles are too big, a loss of performance results.

Not only will many empty pixels be cached (robbing the application of valuable memory), the effect may be unnecessarily asked to render large regions of nothing. For this reason, the max_result_rect must be computed correctly, rather than set to some arbitrarily large size.

Both result_rect and max_result_rect may vary depending on the effect’s parameters, the current time, et cetera; they are valid only for the given invocation of the effect. However, max_result_rect cannot depend on the specific render request. It must be the same no matter what portion of the output is requested by After Effects.

It is legal to return an empty result_rect if the request_rect doesn’t intersect the effect’s output pixels; no rendering need be done.

After Effects may also call the effect with an empty request_rect, meaning the effect is only being asked to compute the max_result_rect.

preserve_rgb_of_zero_alpha can influence the bounds computation process (both result_rect and max_result_rect) and must be respected if the effect behaves differently depending on this setting.