Skip to main content
johnt53984649
Inspiring
April 28, 2019
Question

Create Custom Blending Mode Using SDK

  • April 28, 2019
  • 2 replies
  • 1052 views

I'm brand new to using the AE SDK, and it's quite intimidating coming from the scripting side.

Let's say I want to create my own custom blend mode between layers.  For the sake of simplicity, suppose a is the base layer and b is the blend layer (b is on top of a).  For example, in After Effects, Overlay and Subtract should be implemented something like this:

static overlay(a, b) {

   if (a < 0.5) {

   return 2 * a * b;

   }

   else {

   return 1 - 2 * (1 - a) * (1 - b);

   }

  }

static subtract(a, b) {

   return max(a - b, 0.0)

  }

(these functions are applied to each RGB channel value separately (with pixel channel values that are normalized to be between 0 and 1))

Suppose I want to implement my own custom blend function between two layers, one that After Effects does not provide, such as:

static grain_merge(a, b) {

   return min(max(a + b - 0.5, 0.0), 1.0)

  }

Is this possible with the SDK?  I imagine it would have to be applied as a custom effect, and that's no problem; any way is fine as long as it works.  I know that the base layer (a) would have to be the composite of all the pixels underneath the layer the effect is applied to, and (b) would have to be the source pixels of the layer that the effect is applied to.  But I really don't know how I can actually make this happen.  If this is possible, can you provide an example?

This topic has been closed for replies.

2 replies

Inspiring
May 17, 2021

John, did you ever find a solution for this? I'm trying to do someting similar.

Community Expert
April 28, 2019

yes, it's possible, and yes, it would have to be an effect, as there's no

API for adding a new layer transfer mode to the existing list.

take a look at the "Shifter" sample project in the SDK. it iterates over

pixels and allows making such calculation with very little hassle.

On Sun, Apr 28, 2019 at 9:32 PM johnt53984649 <forums_noreply@adobe.com>

johnt53984649
Inspiring
April 28, 2019

That example helps a little, but I don't understand how I would go about getting the pixels of composite of the layers beneath the layer the effect is applied to.  How would I do that?

Community Expert
April 28, 2019

I'm still not sure how that would work.  I need to know the pixel values of all the layers underneath in order to perform the calculation.  If there's no way to obtain that information, then I don't understand how an adjustment layer would help.  I need both the pixel values of the source layer as well as the values of the composite of all the layers underneath in order to do the calculation.


every effect can get it's "default" input pixel buffer. for regular layer

effects it's either the layer's source (if the effect is the first in the

layer's stack) or the previous effect's output buffer.

in the case of an adjustment layer, the "default" input buffer is the

composite of all underlying layers.

as a secondary input, an effect can get the source of any comp layer

pointed to by a "Layer selector" param. on new AE versions, it can even get

that layer post effects, masks and transformations.

On Mon, Apr 29, 2019 at 12:27 AM johnt53984649 <forums_noreply@adobe.com>