After Effects Expression: Use the luminance of one layer to drive another layer

Posted by & filed under Quick tips.

I recently entered a crazy video competition with some friends. The theme was to bring an outdoor activity inside – and what better outdoor activity is there than a good old Duck Shooting session – with machines guns – in the house.

The competition has now finished and it looks like we attained a really nice third place! To check out the actual video please go here.

While putting this together I wanted to add the muzzle flashes to the guns and also some exposure hits when the muzzle flashes went off. I was already key framing the muzzle flashes and I didn’t want to key frame exposure hits as well. This got me thinking about expressions and how I could use the ‘brightness’ of one layer to drive a value in another layer.

The expression

I did a bunch of research and here’s what I came up with.

exposure = effect("Exposure")(3);
multiplier = 2;

driverLayer = thisComp.layer("MuzzleFlash");
samplePoint = [0,0];
sampleSize = [1280,720];

lightnessSample = driverLayer.sampleImage(samplePoint,sampleSize);
driverLightness = rgbToHsl(lightnessSample)[2];

exposure = driverLightness * multiplier;

 

How it works

So – for this to work you need a single layer with the muzzle flashes – the way I created the muzzle flashes was to buy Video Copilots Action Essentials kit – then I timed the flashes to the underlying video clip – when I had the flashes timed up (I think there were about 5 for this shot) – I then selected all the muzzle flash layers and pre-composed them into a new comp called ‘MuzzleFlash’.

Then I added an adjustment layer above everything and applied the exposure effect to that. You then twirl down the effect properties and add the expression above to the “Master / Exposure” property.

Now be warned – it can take a while to compute. What it basically does is, every frame, it works out the average luminance of the entire Muzzle Flash clip – it then returns a number which we can use to drive our exposure value.

I added the multiplier into the expression so I could get a little more control over the intensity of the exposure hit.

I also found this worked really well as I could duplicate the exposure layer and mask off parts of the actor or surfaces that might be even brighter still – that gave a bit more of an illusion that there really was light emitting from these flashes and lighting up the scene.

Close up of the expression and layers

 

 

8 Comments

  1. Suzanne

    Awesome! I was looking for this about a month ago simply because I didn’t want to “key” the lighting changes that another layer was doing etc. I did manage to find something that worked, but your method is much simpler. Hooray!

  2. Jerry Witt

    I used this script to change the intensity of a light based on the muzzle flashes in some footage. Just deleted the first line and changed exposure to intensity in the last. I had to kick the multiplier up to 200 as well. Very useful script. Thank you Markos.

  3. Terepan

    Hey thnks,,,,,,,,,,,,,,,,grt work
    and plz tell me the color correction curve of “The Vampire Diaries” if u can,,,,,,,,,,,, bcoz ordinary camera shooting look quite worse,,,,,,,,,,,, so PLZ do tell me will b thnkful to u

    and ya Some correction curve of horror movies types

    thnks :))

  4. Markos

    Hi Terepan. I think its pretty individual for the look that you are going for. I couldn’t tell you the curve because I havent seen the show – probably the easiest way would be to grab a piece of footage and just experiment with the curves until you find a look you like.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>