FORUMS: list search recent posts

# Calculating overlying opacities...

FAQ   •   VIEW ALL
 Calculating overlying opacities... on Nov 3, 2015 at 11:34:39 am

Situation:
I have an object - a simple shape layer rectangle - that is duplicated and sits on top of the original - let's call these objects A1 and A2.

Elsewhere (not overlapping) I have object B.

All three objects are fed with the same opacity value from a slider.

I'm trying to find the correct expression / math function to adjust the opacity of the 'A' objects to get a 'total' opacity to match the 'B' object...

http://mikeabbott.info
http://vantagegraphics.co.uk

 Re: Calculating overlying opacities...on Nov 3, 2015 at 12:17:50 pmLast Edited By Xavier Gomez on Nov 3, 2015 at 12:19:19 pm

If you have two layers "TOP" and "BOT", and set
top = layer("TOP").transform.opacity/100;
bot = layer("BOT").transform.opacity/100;

then the resulting opacity is: total = 100*(top+bot-top*bot)

So you have to "solve" total = layer("B").transform.opacity;
which does not always have a solution, because opacity is clamped to the range [0,100].

If you leave the top layer opacity free and set the expression in the bottom layer, it would be:

```top = layer("TOP").transform.opacity/100; other = layer("B").transform.opacity/100; top == 1 ? value : 100*(other-top)/(1-top);```

(when the opacity of the top layer is 100, the bottom layer is completely hidden - unless its shape/scale has changed).

Else if you want to control the bottom opacity, the expression for the top layer would be:
```bot = layer("BOT").transform.opacity/100; other = layer("B").transform.opacity/100; bot == 1 ? value : 100*(other-bot)/(1-bot);```

Xavier.

 Re: Calculating overlying opacities...on Nov 3, 2015 at 1:39:57 pmLast Edited By Mike Abbott on Nov 3, 2015 at 2:40:11 pm

I was thinking I would need some 'curve based' function.

As the opacity slider value varies so does the relationship between the two layers. That's the mathematical relationship I'm trying to get my head around.

I suspect the curve will tail off - so it will need to be clamped at either extreme...

Mike

http://mikeabbott.info
http://vantagegraphics.co.uk

 Re: Calculating overlying opacities...on Nov 3, 2015 at 3:08:15 pm

I think it would be like this:

s = clamp(thisComp.layer("control").effect("Slider Control")("Slider"),0,100)/100;
(1-(1-s)*(1-s))*100

Dan

 Re: Calculating overlying opacities...on Nov 3, 2015 at 3:32:55 pm

Dan,
Many thanks for your contribution - as always.

Your suggestion works OK for the extremes - but doesn't elsewhere. I'm trying to maintain a matching opacity between the the stack of two 'A' shapes and the single 'B' shape *throughout* the opacity range from 0 to 100%.

http://mikeabbott.info
http://vantagegraphics.co.uk

 Re: Calculating overlying opacities...on Nov 3, 2015 at 5:14:17 pm

I had missed the slider thing, didnt see.
You have 3 opacities and just one slider, so it's not clear what the slider is expected to do.

These 2 expressions assume that the slider value (range 0-100) gives the percentage opacity layer "A1" gets, and the second one adjusts the opacity for layer "A2"

A1:

```B = thisComp.layer("B").transform.opacity; pc = clamp(thisComp.layer("CONTROLLER").effect("A1 percent")("Slider"), 0, 100)/100; B*pc;```

A2:

```B = thisComp.layer("B").transform.opacity/100; pc = clamp(thisComp.layer("CONTROLLER").effect("A1 percent")("Slider"), 0, 100)/100; A1 = B*pc; A1 == 1 ? 0 : 100*(B-A1)/(1-A1);```

Xavier

 Re: Calculating overlying opacities...on Nov 3, 2015 at 5:54:10 pm

It works for me. What issues are you seeing?

Dan

 Re: Calculating overlying opacities...on Nov 14, 2015 at 5:16:54 pm

Dan,
Apologies for the delay in response - but I just wanted to say thanks for your help on this - yes, your solution did work, I was getting tripped up by some other complexities in the project in which I was using it.
It's all sorted now - and I very much appreciate your help.

Mike

http://mikeabbott.info
http://vantagegraphics.co.uk