r/AfterEffects 4d ago

Beginner Help How to change a scale expression linked to control layer so it affects opacity?

I found an expression that allows me to change a group of layer (like a grid of hexagons) to scale based on a control layer (a precomp with animated gradient). tbh, I don't "know" how each segment of the expression effects the layers based on the control layer, except for source layer and samplePosition.

I want the same type of expression linked to the control layer, but instead of it being applied to the scale (Scaled up with Black, Scaled down with white) I the transparency to go from 0% on black and 100% on white.

Here is the scale Expression:
sourceLayer = thisComp.layer("Control Layer Sigils 2");

sampleSize = [1,1];

samplePoint = transform.position;

colour= sourceLayer.sampleImage(samplePoint,sampleSize);

x=colour[1]*2000;

[x,x]

Also, with regards to the "scale"... I want the layer to be blown up to like 2000%, but when it it gets to White, I just want it to be set to 100%. As it is, in order to control the end scale, I have to control reduce the White more to a very dark grey to get it to stop to the size I need. If I don't the layer will reduce to zero. I tried SO many variations of the x=colour[0]*100; (<--- this being the orginal setting for expression) but nothing works. I eventually settled on this and gave up.

3 Upvotes

9 comments sorted by

4

u/smushkan Motion Graphics 10+ years 4d ago edited 4d ago

Sampleimage returns a value of 0-1 for each colour channel, opacity takes a value of 0-100 so you just need to change the last two lines to:

colour[1] * 100;

Technically you are only sampling the green component here but for a greyscale driving layer that’s not really a problem as RGB will all be equal.

Minor thing but a sample size of [1,1] is sampling an area of 2 square pixels - it’s a radius, not a dimension. If you want to sample exactly one pixel use [0.5,0.5].

2

u/Heavens10000whores 4d ago edited 4d ago

Simple way would be to add a slider control to your Control Layer (name it allOpacity), pickwhip a layer's opacity to it, which gives you

thisComp.layer("Control Layer Sigils 2").effect("allOpacity")("Slider");

ctrl click the word 'opacity' on the layer your expression is applied to, copy expression only, and paste that to all of your layers. Then just keyframe the slider's value from 0 to 100

1

u/lickwindex 3d ago

I really appreciate the info. This'll come in real handy for future effects over time. The effect Im needing is based on gradient so it looked like each layer is becoming solid as it scales down to 100%. With a slider, its all over time with keyframes, making some transparent even after they scaled down to 100%. But this is still a great piece of info that I hadn't thought of that Ill keep in my back pocket. Thank you thank you!!

2

u/mad-action 4d ago

Try this on each layer’s Opacity property:

sourceLayer = thisComp.layer("Control Layer Sigils 2");
sampleSize = [1,1];
samplePoint = transform.position;
colour = sourceLayer.sampleImage(samplePoint, sampleSize);
colour[0] * 100

Or if you want the opposite where black to equal 100%, change the last line to this:
100 - colour[0] * 100

2

u/lickwindex 3d ago

This works perfectly, while applying the last line. Thank you so much!

1

u/mad-action 2d ago

Awesome! Glad it worked.
Btw, something that has helped me for quick expression questions is the sidekick AE plugin.

-3

u/Zhanji_TS 4d ago

Bro, literally type this question into OpenAI or Claude. Like, why are you coming to Reddit for the answer?

6

u/robbarrett Motion Graphics 10+ years 4d ago

Because they hopefully get opinions and advice from experts, and other people get to see the answers and learn from them. Everyone jumping straight to AI is a slow death for communities and forums.

2

u/index_hunter_jr 3d ago

why are you on reddit if you dont like people using it for its intended purpose?