Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions sampleImage + Trapcode Particular – If sample area is not a specific color, emit particles

  • sampleImage + Trapcode Particular – If sample area is not a specific color, emit particles

    Posted by Shahid Raza on October 20, 2018 at 7:46 pm

    I’m working on a little Particular effect where I want to generate the “Particles/sec” based on a different comp’s animations in the project.

    Particular Comp:
    – Solid with Trapcode Particular applied. Position of this solid is dynamic (let’s use [50,850] as an example for this).

    Second Comp:
    Multiple shape layers animating vertically from top to bottom of the comp using keyframes.

    Both comps are 8160 x 850 px

    The Idea
    The expression will be added to Particular Comp solid’s “Particles/sec” property.
    Using the X/Y position of the Particular Comp solid, I’d like to sample the Second Comp at this point with a 3 pixel square.
    If this area is not a specific HEX color or not the comp’s background color, I’d like to change the Particles/sec to 1000.
    Otherwise the Particle/sec should be set to 0.

    How can I achieve this? Thanks!

    Filip Vandueren replied 7 years, 9 months ago 2 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    October 20, 2018 at 10:09 pm

    Personally, I would leave the layer stationary and animate the Emitter’s position, not the entire layer.

    For some reason just comparing samplecolor to [0,0,0,0] doesn’t work, hence the toSource and extra quotes. The spaces between the comma’s matter too…

    for troubleshooting or finding out the perfect color-numbers for your case:
    plug a sampleImage() into the sourceText of a text-layer, that way you can see the actual values.

    good luck.

    l=thisComp.layer("target");
    // first do some voodoo to get parented, scaled, or not precisely aligned layers to work seamlessly
    p=l.fromComp(thisLayer.toComp(anchorPoint));

    // sample th target layer
    sampleColor = l.sampleImage(p , radius = [3, 3], postEffect = true, t = time);

    if (sampleColor.toSource()=="[0, 0, 0, 0]") { // change this to your color value
    0;
    } else {
    1000;
    }

  • Shahid Raza

    October 21, 2018 at 10:54 am

    Thanks for your help Filip, this does point me in the right direction.

    Sorry I wasn’t too clear before. I am actually changing the Emitter Position rather than the layer position.

    Here’s what I’m actually trying to achieve:

    The sampleImage() area needs to be detecting “Animations” comp, based off the “Particular” comp’s “red square particles” Emitter Position.

    I didn’t quite understand the l and p variables in order to modify the code you gave.

    Would appreciate it if you can help explain these or update the code for me ☺

    Thanks!

  • Filip Vandueren

    October 21, 2018 at 11:59 am

    So if I understand correctly, the layer with the particle system is in an entirely different composition than your “map” with shapes that shows where the emitter should be active ?
    That comp is not available as a (hidden) layer inside the comp with the emitter ?
    That would make it harder because you would need to sample every layer of your shapes-comp…
    -> So just add the “animation” comp as a layer to your “Particular” comp, and then make the layer invisible.

    Another complicating factor is that your Particular setup could be 3D: is there an (animated) camera, is the emitter’s position’s Z-value varying over time, or is it always at Z=0 ?
    If it’s not just a ‘flat’ particle system, we need to transform the 3D position of the emitter to a 2D position for sampleImage.

    The easiest way to tackle this is to add a Null-layer, make it 3D and give its position this expression:
    thisComp.layer("red square particles").effect("Particular")("Position")

    Then we’ll use this Null-layer as our reference and the expression below should hopefully work for you now…

    sl=thisComp.layer("Animation"); // the layer to sample from
    pl=thisComp.layer("Null 1"); // the layer that represents the 3D location of the emitter
    // first do some voodoo to get parented, scaled, or not precisely aligned layers to work seamlessly
    pos2d=sl.fromComp(pl.toComp(pl.anchorPoint));

    // sample th target layer
    sampleColor = sl.sampleImage(pos2d , radius = [3, 3], postEffect = true, t = time);

    if (sampleColor.toSource()=="[0, 0, 0, 0]") { // change this to your color value
    0;
    } else {
    1000;
    }

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