Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions DIY depth of field

  • DIY depth of field

    Posted by Nick Hill on January 8, 2010 at 3:16 pm

    My math(s) isn’t up to this.

    I have a camera pointing at a bunch of 3d layers to which I want to add depth of field. The default depth of field looks pretty horrible (they’re stark black and white so the box blur effect is obvious). I tried using the lens blur effect with a custom map, but when the layers move in 3d this stops working, plus it takes ages to calculate. So, I thought I’d improvise – applying a gaussian blur effect to each layer, than determining how much to blur it by its distance from the camera’s focal plane, multiplied by a slider value. It’s imperfect (and wouldn’t work for a layer that’s almost at 90 degrees to the camera of course, where the back is significantly further away than the front) but it’ll do.

    The problem is that I can’t work out how to calculate a plane which is normal to the camera direction (centred on the point of interest) and then the shortest distance from the target layer to this plane. Any ideas?

    Nick Hill replied 16 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    January 8, 2010 at 4:13 pm

    Something like this should work:

    mult = .1; // your blur amount slider goes here
    C = thisComp.layer(“Camera 1”);
    v1 = toWorld(anchorPoint) – C.toWorld([0,0,0]);
    v2 = C.toWorldVec([0,0,1]);
    d = length(dot(v1,v2),C.focusDistance);
    d*mult

    Dan

  • Nick Hill

    January 8, 2010 at 4:57 pm

    Thanks Dan! A maths wizard as ever 🙂

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