Control Optical Flares brightness from light/cam orientat'n?

Scripting for After Effects

Control Optical Flares brightness from light/cam orientat'n?

Postby howiem on 12/4/2016, 7:27 am

In real life, with a real spotlight (in the broadest sense) there's should be a bigger lens flare if the light's pointing directly into the camera (or, ideally, if the camera is within the spotlight's cone), but if the spot is pointing to the side, a smaller flare, and if it's pointing completely away, no flare.

I've got a spotlight dancing round the screen for 4 minutes (long story). Optical Flares and Trapcode Lux let me see the beam, but to really sell its movement, I need to modulate the brightness of the flare.

Been keyframing it so far, and it looks ace, but it's waaay too much work to do for the whole sequence and seems ripe for some expression love.

So:

I'm guessing:
- camera orientation can be ignored, as that just affects the light's position in the frame, and that's handled by OF.
- so it's really about the angle between the light's orientation and an imaginary straight line joining the light to the camera.
- then I can map that angle to brightness (possibly taking into account the light's cone angle).

Has anyone any tips on how I work out this angle? Is there a nice simple AE function or two that could help out? I think I can probably work it out with school-level trig, but I bet there's some clever matrixy thing that'll do it quicker..?
howiem
 
Posts: 22
Joined: 02/14/2013, 10:27 am

Re: Control Optical Flares brightness from light/cam orientat'n?

Postby JPT7505 on 12/4/2016, 1:13 pm

There's a tutorial for something similiar on the site that should work. Dynamic triggering.

https://www.videocopilot.net/products/opticalflares/

Towards the bottom.
JPT7505
 
Posts: 775
Joined: 02/9/2011, 8:17 am

Re: Control Optical Flares brightness from light/cam orientat'n?

Postby howiem on 12/4/2016, 1:38 pm

Dynamic triggering is more about creating effects as the light source moves across the frame border, but I can't see any way to configure it so it takes the light source's orientation into consideration.

I've got a bit further with my exploration (summat to do with dot products), will report back if I suss it.
howiem
 
Posts: 22
Joined: 02/14/2013, 10:27 am

Re: Control Optical Flares brightness from light/cam orientat'n?

Postby krisq on 12/5/2016, 2:10 am

howiem wrote:Dynamic triggering is more about creating effects as the light source moves across the frame border, but I can't see any way to configure it so it takes the light source's orientation into consideration.

I've got a bit further with my exploration (summat to do with dot products), will report back if I suss it.

FYI, you can change the type of dynamic trigger from border to center or to light.
Just make sure you're not overthinking the effect.
krisq
 
Posts: 407
Joined: 08/3/2008, 9:52 am

Re: Control Optical Flares brightness from light/cam orientat'n?

Postby howiem on 12/5/2016, 3:12 am

Hehehe - I could well be overthinking things. But none of the dynamic trigger options relate to the light's orientation, only to its position.

Imagine a lighthouse, static in the frame. You'd probably need two elements to sell it - the light beam, and a lens flare at the light source. Thinking just about the flare, as the light turns towards us, the flare gets brighter and brighter until it's pointing directly at us, then fades to almost nothing as the light rotates past and away again.

Or the old X-files style "people with torches in the woods at night" shot - as a torch scans past the camera, you get a brighter beam, of course (atmospheric anisotropy) but you also get a sudden brightness in the lens flare. And none of this relates to the light position, it's all about the light direction/orientation.

Bottom line is, if I keyframe the brightness, it absolutely sells the effect - even with just a (Trapcode Lux) light beam and a lens flare, the viewer instantly understands which way the light is "looking" as it scans round. But I've got so many shots to do, and I keep having to revise/refine them, so I've gotta automate it somehow.
howiem
 
Posts: 22
Joined: 02/14/2013, 10:27 am

Re: Control Optical Flares brightness from light/cam orientat'n?

Postby howiem on 12/6/2016, 4:28 am

OK, sussed it (with a bit of help from the ever-fragrant Dan Ebberts).

To see it in action, create a comp with a spotlight and a camera, and add a solid with VC Optical Flares, set to track lights.

Apply this expression to the Flare Brightness parameter. Now as you move/spin the spotlight round, the flare will dazzle the camera realistically as it points toward it. The script respects the spot's cone angle and feather.

Sorta feel that this ought to be done by the plugin... something for the next version perhaps? :)

Code: Select all
// AE expression to modulate a spotlight's flare brightness
// depending on whether the spot is facing into or away
// from the camera
// h 6/12/2016

// change these to reference your spotlight
// and camera as appropriate

L = thisComp.layer("Light 1");
C = thisComp.activeCamera;

// maximum and minimum brightness
// these are multiplied by the existing brightness
// parameter, so you can still tweak the overall
// flare brightness in the usual way

maxBrightness = 1;
minBrightness = 0.2;

// our calculations are based on 0 --> 180
// light pointing AT camera --> AWAY from cam
// so halve the light cone angle for simplicity

coneAngle = L.lightOption.coneAngle / 2;
coneFeatherAngle = coneAngle - (coneAngle * L.lightOption.coneFeather * 0.01);

// work out the angle between the light's direction
// and the vector between camera and light
// (all credit Dan Ebberts)

v1 = normalize(C.toWorld([0,0,0]) - L.toWorld([0,0,0]));
v2 = L.toWorldVec([0,0,1]);
relativeAngle = radiansToDegrees( Math.acos (dot(v1,v2)))

// map the angle to the brightness multipliers

if (relativeAngle <= coneFeatherAngle) {
   output = maxBrightness;
} else {
   if (relativeAngle >= coneAngle) {
      output = minBrightness;
   } else {
      output = linear (relativeAngle, coneFeatherAngle, coneAngle, maxBrightness, minBrightness);
   }
}

// multiply our final output multplier by
// the existing brightness parameter

output * value
howiem
 
Posts: 22
Joined: 02/14/2013, 10:27 am


Return to After Effects Expressions