Tutorial 202: Depth Matte
Joe Clay | Jan 13, 2020
Sev, Andrew Embury, and I were working on a project using Redshift. For some reason, depth passes from Redshift are true depth passes—i.e. there's no info for focus. The depth is basically colored solely based on distance to camera.
Unfortunately, that means that keeping something in focus inside of After Effects is rather tedious since you can't just select a single grey value and be set. Instead, you have to keyframe the entire sequence so that your focus point is maintained. If you could tell Frischluft or Camera Lens Blur to stick to a point, then you could at least track a spot to keep in focus. Unfortunately, the focus selectors aren't keyframeable. So instead, I built my own workaround, as you'll see in this tutorial.
Expression Code
Here's the code to grab color from the center point of a mask. Remember to set up a Layer Control! Note, from the tutorial, I've removed the hardcoded [1280,720]
and replaced it with [thisComp.width/2, thisComp.height/2]
so you don't have to deal with that. If you have more than one mask on your layer, you might need to pick a different one when you set up the pt
variable.
function getPoint(msk) {
pts = msk.points();
x = y = 0;
for(i = 0; i < pts.length; i++) {
x += pts[i][0];
y += pts[i][1];
}
x = x/4;
y = y/4;
return [x,y];
}
L = effect("Layer Control")("Layer");
pt = getPoint(mask("Mask 1").maskPath) + [thisComp.width/2, thisComp.height/2];
L.sampleImage(pt, [10,10], true);
Apply the next expression to a Slider Control. I made it a Master Property to get its data to the parent comp, but since you should bake this expression anyway, you can just bake the slider and copy it to the main comp if you want. The Master Property setup is nice because it's easy to test it before you bake it and if you need to change it, you just turn the expression back on and then bake it again. And as I mentioned in the tutorial, if you invert your matte in your blur plugin you might be able to remove the 255 -
bit.
255 - (content("Rectangle 1").content("Fill 1").color[0] * 255);
Become a Patron
If you'd like to help support Workbench, check out our Patreon page. For $5 a month, you get access to all of the tutorial project files we've made available as well as other monthly projects, rigs, R&D, elements, early product previews, and BTS content not available anywhere else!