Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Expression efficiency (sampleImage)

  • Expression efficiency (sampleImage)

    Posted by Adam Cole on October 30, 2012 at 3:47 pm

    An RGB value from one layer needs to affect another layer’s Opacity and Scale. So there are two options – use the sampleImage function in both scale and opacity OR reference scale in opacity:

    Scale
    target = thisComp.layer(“Layer1”);
    value = target.sampleImage([x,y],[5,5])[0]*100;

    Opacity
    target = thisComp.layer(“Layer1”);
    target.sampleImage([x,y],[5,5])[0]*50;

    —–OR——

    Scale
    target = thisComp.layer(“Layer1”);
    value = target.sampleImage([x,y],[5,5])[0]*100;

    Opacity
    transform.scale[0]*0.5

    Is on of these options more efficient/faster/will cause me less trouble?

    Darby Edelen replied 13 years, 11 months ago 3 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 30, 2012 at 4:05 pm

    I’m not sure about performance–I suspect that sampleImage() gets run twice per frame either way, but I’d say try it both ways and find out.

    Style-wise, I like the second way because it lets you tweak the sampleImage() parameters in one place.

    Dan

  • Darby Edelen

    October 30, 2012 at 5:33 pm

    I agree with Dan. I’d also add that if one is going to be faster it’d be the 2nd one, but if there is a speedup it may not be noticeable.

    Reducing the sample size should add a little to any speed gains.

    Also note that sampleImage() expressions disable ‘Render Multiple Frames Simultaneously.’ For this reason I almost always convert the expression to keyframes before I kick out my final render. This can be a pain if you need to adjust the expression later, so I only recommend it once you’re happy with the results. This command is run with the properties you want to bake selected and is located here:

    Animation > Keyframe Assistant > Convert Expression to Keyframes

    Darby Edelen

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