Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Calculating overlying opacities…

  • Calculating overlying opacities…

    Posted by Mike Abbott on November 3, 2015 at 11:34 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…

    I think I need to learn more math… : )

    Can anyone help – please?

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

    Mike Abbott replied 10 years, 9 months ago 3 Members · 7 Replies
  • 7 Replies
  • Xavier Gomez

    November 3, 2015 at 12:17 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.

  • Mike Abbott

    November 3, 2015 at 1:39 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

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

  • Dan Ebberts

    November 3, 2015 at 3:08 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

  • Mike Abbott

    November 3, 2015 at 3:32 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%.

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

  • Xavier Gomez

    November 3, 2015 at 5:14 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

  • Dan Ebberts

    November 3, 2015 at 5:54 pm

    It works for me. What issues are you seeing?

    Dan

  • Mike Abbott

    November 14, 2015 at 5:16 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

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

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