ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Shahid Raza
sampleImage + Trapcode Particular - If sample area is not a specific color, emit particles
on Oct 20, 2018 at 7:46:24 pm
Last Edited By Shahid Raza on Oct 20, 2018 at 8:27:31 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!


Return to posts index

Filip Vandueren
Re: sampleImage + Trapcode Particular - If sample area is not a specific color, emit particles
on Oct 20, 2018 at 10:09:27 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;
}




Return to posts index

Shahid Raza
Re: sampleImage + Trapcode Particular - If sample area is not a specific color, emit particles
on Oct 21, 2018 at 10:54:06 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!


Return to posts index


Filip Vandueren
Re: sampleImage + Trapcode Particular - If sample area is not a specific color, emit particles
on Oct 21, 2018 at 11:59:20 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;
}




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]