Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions luma of an area drive expression?

  • luma of an area drive expression?

    Posted by Jiri Fiala on October 31, 2008 at 8:17 pm

    Hello guys! I need to fake reflection off a cinema screen onto spectators` faces (looking towards the camera). I have a guy waving a flag before a light, which makes nice impression of cinema projector rays reflecting on backs of spectators` heads. That`s fine.

    Now, I need to synchronize this blinking with adjustment layer throwing fake light on spectators` faces from front. I think it could work with sampleImage expression. I looked up Dan Ebberts` wonderful expression (“Obscuration with sampleImage, https://www.motionscript.com/design-guide/obscuration.html), but that works with alpha. I need it to work with Luminance. It would basically sample an area from existing footage and use this data to drive opacity of another adjustment layer.

    Could anyone help me modify this expression? Thanks!

    Jiri Fiala replied 17 years, 6 months ago 2 Members · 7 Replies
  • 7 Replies
  • Kevin Camp

    October 31, 2008 at 9:31 pm

    in dan’s expression:

    alpha = target.sampleImage(effect(“Lens Flare”)(“Flare Center”),[3.5, 3.5])[3];

    the [3] is the alpha component of rgba. so [0] would be red, [1] would be blue, etc…

    there is another function that will convert rgb values to hsl values… if you worked that into dan’s expression it might look like this:

    target = thisComp.layer(“clouds”);
    lum = rgbToHsl(target.sampleImage(effect(“Lens Flare”)(“Flare Center”),[3.5, 3.5]))[2];
    linear(lum, 0, 0.36, 80, 10)

    the [2] relates to the luminance component of hsl and should retrieve just that value for your expression…

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Jiri Fiala

    October 31, 2008 at 10:10 pm

    It will take me some time to wrap my head around this, but thank you very much Kevin! Will try that tomorrow.

  • Kevin Camp

    October 31, 2008 at 11:38 pm

    the expression seems complicated, but if you break it down the basics are simple…

    the function rgbToHsl() will convert any rgba value within the () to hsla values.

    so if you had a grey rgb value like this [.5,.5,.5,1] (remember the last value is alpha) and put it into the rgb to hsl function, like this: rgbToHsl([.5,.5,.5,1]) it would give you a value of [0,0,.5,1]. so that would red as no hue, no saturation 50% luma (or lightness) and opaque (alpha full on).

    if you only wanted the luma value, your expression would be like this: rgbToHsl([.5,.5,.5,1])[2]; again,the [2] just denotes that you only want to return the 3rd value from hsla, the luma value. so the result would be ‘.5’

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Jiri Fiala

    November 1, 2008 at 12:58 am

    I think I understand, but I had a hard time understanding the index: so the [2] means “skip the first two members of an array”? Would [1] mean “return saturation value”?

    Thanks for your excellent help.

  • Jiri Fiala

    November 1, 2008 at 9:25 am

    I am sorry but I am rather confused. I am unable to modify the expression to suit my needs :(.

    I need a brightness of a sample area (say 20×20 pixels) of layer “footage” (let`s say from coords 20,300 – close to mid left edge of screen. The area stays the same) to translate to opacity of layer “flicker”.

    Please help, thanks!

  • Kevin Camp

    November 1, 2008 at 4:49 pm

    to answer your prior post, yes, [1] would return just the saturation value.

    some thing like this may work for you:

    target = thisComp.layer(“footage”); //this need to point at your footage layer
    samplepoint= [20,300];
    samplesize= [20,20];

    lum = rgbToHsl(target.sampleImage(samplepoint,samplesize))[2];

    linear(lum, 0, 1, 20, 80)

    i don’t have cs3 at home, so i can’t test this (sampleImage was introduced in cs3), but i think it should work. the first 3 lines are variables, you need to make sure the target is your footage layer. you can modify the samplesize and samplepoint as needed.

    the samplepoint is relative to the footage layer, not the comp. what that means is if the footage is the same size as the comp and not repostioned, no problem. but if it is different, then the easy solution would be to add a point control effect (from expression controls) to the footage layer, then direct the samplepoint to the point control effect. so that line might look like this:

    samplepoint=target.effect(“Point Control”)(“Point”);

    you can then just move the point control point around to sample different areas of the footage…. it may be the easier way to go if you wanted to start this way.

    the last line will take some adjusting, based on your footage and what you are going for. the first 2 numbers (0,1) are the input range. you may want to tighten these based on your footage, maybe (.25,.75) or something to get a better sample.

    the last 2 numbers are the output range… if you were applying this to say opacity, the you coulg go use (0,100) for full range, but iff you didn’t want the value to drop bellow 30 or get higher than 70, the you would use (30,70) for the output range…

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Jiri Fiala

    November 3, 2008 at 6:55 pm

    I can’t thank you enough Kevin! That’s exactly what I needed. Now I can fake even more stuff with AE 😀

    Thanks again!

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