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

there's no API for getting all lower layers composited together. your user

can apply that effect on an adjustment layer to achieve this result.

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