ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

smoothly control opacity of multiple layers with one slider

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Florian Motz
smoothly control opacity of multiple layers with one slider
on Jul 20, 2017 at 11:57:38 am
Last Edited By Florian Motz on Jul 20, 2017 at 12:00:10 pm

Hey,
a post from 2009 suggested:

Slider in a "Control" layer and posting this Code to the other layers opacity:

visibleOne = thisComp.layer("control").effect("Slider Control")("Slider");
if (Math.floor(visibleOne) == index)100 else 0


My question now is, how can I extend the Code to get smooth transitions between multiple layers? In the end my slider should smoothly blend between n layers.

My thoughts and Code so far:
- divide a slider range (e.g. 0 - 100) into n parts (n - number of layers in the comp)
- use the in-built linear function to map the layer opacity to a number range of the slider


slider_val = thisComp.layer("Opacity Control").effect("Einstellungen für Schieberegler")("Schieberegler");
num_layers = thisComp.numLayers - 1; // total number of layers minus the control layer at the bottom
start = (index - 1) / num_layers * 100; // depending on the layer index, start slider value for the opacity transition
end = index / num_layers * 100; // depending on the layer index, end slider value for the opacity transition

if (slider_val >= start && slider_val < end){
linear(transform.opacity, 0, 100, start, end ); // doesnt work as intended
}else{
0;
}


I wanted to make the script as versatile as possible, so that I didnt need to change any fixed values (like the total amount of layers) in the script when adding/ removing layers.

Does anyone have an idea?

Cheers Fl0


Return to posts index

Florian Motz
Re: smoothly control opacity of multiple layers with one slider
on Jul 20, 2017 at 3:07:56 pm

I came up with the following longish solution:

Copy the Code into each layers opacity:

slider_val = thisComp.layer("Opacity Control").effect("layer opacity")("Slider");
extra_layers = thisComp.layer("Opacity Control").effect("extra layers")("Slider");
num_layers = thisComp.numLayers - extra_layers;
start = (index - 1) / num_layers * 100;
mid = index / num_layers * 100;
end = 2 * mid - start;

if (slider_val >= start && slider_val < mid) {
transform.opacity = (slider_val.value - start) * num_layers
} else {
if (slider_val >= mid && slider_val < end ) {
transform.opacity = 100 - (slider_val.value - mid) * num_layers
}else{
0;
}}


Make sure to name the
- Control Layer: "Opacity Control"
- Slider Effect: layer opacity
- Slider Effect: extra layers

If there is any simpler solution, I'd like to see it.

Cheers,
Fl0


Return to posts index

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