Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Link effect parameter to luminosity

  • Link effect parameter to luminosity

    Posted by Anthony Diehl on June 11, 2013 at 7:00 pm

    Ok, here is what I’m trying to do:

    I have a AE comp filled with layers from an AI files. Its a big grid of triangles. I want to place an effect (lets say a transform effect, using just the scale parameter), on each layer and have a parameter on that effect dynamically change based on the luminosity of another layer.

    For example, I create a layer with a white ellipse with feather edges and move it around the comp. Now every layer will scale larger or smaller based on how bright the pixels are, relative to that layer. The white ellipse moves away from the layer, its scales smaller. The ellipse moves closer, and the layer scales larger. I would obviously hide the ellipse in this example and just be using it to control the effect parameters on each layer. So, I could create a complex scaling effect across a lot of layer just by moving the ellipse layer around.

    The idea is that I could then link this type of expression to other types of effect parameters, like glow, etc to get some complex things happening fairly easily.

    Any idea how to link a layers effect parameters to luminosity like this? Of perhaps it could be done by linking to a null object somehow? I just assume the luminosity would be more intuitive by using gradients to have soft changes in parameters.

    Any help is super appreciated!

    thanks

    Anthony Diehl replied 13 years, 3 months ago 3 Members · 4 Replies
  • 4 Replies
  • Todd Kopriva

    June 12, 2013 at 6:37 am

    It might be rather slow to process, but you could use the sampleImage expression method to sample the color data from the layers.

    ———————————————————————————————————
    Todd Kopriva, Adobe Systems Incorporated
    After Effects quality engineering
    After Effects team blog
    ———————————————————————————————————

  • Anthony Diehl

    June 12, 2013 at 6:42 am

    Thanks for the reply! Ya, I have another similar comp that is using this method to recolour a bunch of layers based on another layer that is sampled. It works great, but I just copy and pasted some script I found online.

    How exactly would I use sampleImage to get usable data that I can then link to an effect parameter?
    I guess I want to look at luminosity or alpha somehow, yes?

    I’m really green when it comes to expressions like this. ANy examples of expression code that would work?

    thanks!

  • Darby Edelen

    June 13, 2013 at 4:47 pm

    The sampleImage() function returns a color as a 4-component vector in this form: [red, green, blue, alpha]. The ranges of the values are 0-1. You can convert these to Hue/Saturation/Lightness values and then sample just the lightness like this (I’m including some variables that stand in for things like the “point” and “radius” for the sampleImage function):


    c = sampleImage(point, radius);
    lum = rgbToHsl(c)[2];

    The [2] component of the HSL version of the color is the lightness. Also, it’s important to note that the “point” variable is not a composition or world point, but one in the layer’s local space.

    Once you have that value you can use it with a linear() or ease() function to remap the 0-1 range to another range, here’s an example for scale:


    linear(lum, 0, 1, [50,50], [150,150]);

    Which would vary scale from 50% to 150% on X and Y axes for a 2D layer as the brightness of the layer being sampled goes from 0 (black) to 1 (white).

    I’m not covering all the details of implementation, so if you’re new to expressions/JavaScript you’ll likely have lots of additional learning to do in order to make this happen.

    Also, if you are going to use an easily defined shape like a circle, ellipse, box or rectangle then I wouldn’t use sampleImage() but rather use code to drive the expression. It would evaluate much faster.

    Darby Edelen

  • Anthony Diehl

    June 14, 2013 at 8:02 am

    Sweet, thanks. I played around with this method. Could;t get it working, but thats probably because I’m just super new to building out longer expressions.

    I did manage to find a method that worked by piecing together a few other examples I found.


    target = thisComp.layer("Expand");
    alpha = target.sampleImage(transform.position, [width, height]/2, true, time)[3];
    ease(alpha, 0, 1, 0, 100)

    I have a pre-comped layer (“Expand”) that has a variety of masks, ramps, etc. I am sampling the alpha value on that layer and putting this expression in to control the scale value of the Transform effect on about 150 small layers which are arranged in a big grid. Its kind of slow to render but otherwise works great. I can get some cool effects and really complicated patterns going by just tweaking my “Expand” layer.

    Thanks for the feedback.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy