Realistic Depth of Field Calculator in Flame

Demo movie:

Renders are cheap and geo has issues, but you can get the idea.

1. Enter sensor and lens info.

2. In Action set camera position and AIM.

3. Adjust DoF node or other defocus tool (needs Z depth) using Near and Far planes as ref.

https://vimeo.com/405260515

Flame 2020.1.2 setups to try:

https://www.dropbox.com/sh/fvh6htb07c8wh2p/AAC8XdoahusJpizQGEAwQvhva?dl=0

One w NoGeo (smallest), one w moCap guys, one w FBX geo (largest)

Instruction pics:
What is DoF?

Depth of Field is the distance in the Camera View that appears sharp. It’s what’s “in-focus”.

Relationship of camera sensor size, focalLength of lens (50mm), and fStop of lens (2.8, 4.0) define how deep an area is seen as sharp.

Everything between Near and Far is in focus.

Changes in fStop or focalDistance will affect results accordingly.

The achieve the same framing, the same Field of View on a larger sensor, requires a longer lens and with some camera position adjustment. 

To get similar framing to a 50mm lens fitted to a 35mm sensor, you might use a 75mm lens on an AlexaLF sensor, and move camera forward/back a bit to adjust.

No matter the sensorSize, the DoF is relationship of focalLength and fStop.  A 50mm lens at f4 will give same DoF on both sensors, but changing to the 75mm will give you a shallower DoF.  To widen the DoF you could change the fStop to a higher number.

Note: fStop in real world controls how much light gets to sensor.  This setup doesn’t make any adjustments to image brightness result.

Scale of scene

Setup provided is already set up in mm. Offset of X or Z axis by 1000 should line up correctly.

Recreate in default Action: Go to Action node prefs Ruler and click define. change from 400 to 1000 and click off define. Bring in reference FBX for oneMeter_square. Units should be 1000.

Reference:

Find an online source for sensor size info.

I used pCam Pro app to verify results of the expressions.  

Seemed to be within a few centimeters in most cases.

Creating variables in Flame:

Equations are well documented on internet. Websites from ARRI, Panavision, Yedlin.net, Wikipedia, etc. were very helpful.  Links at end.

Edited a GLSL shader that ships w Flame called UI_Only.

Created variables for sensor size, lens focal length, focus distance, etc.

Also helpful for translating weird looking math equations to something readable.

Animating focalLength should emulate a zoom lens.

Expression examples: (use similar math if recreating in other apps)

sensorD: sqrt((sensorHoriz * sensorHoriz) + (sensorVert * sensorVert))

entryPupil: (focalLength/unitScale)/fStop

blurMax: entryPupil * (((hyperfocal * 2) – focusDistance)/hyperfocal*2) * unitScale

fov: degrees(2 * atan(sensorHoriz/(2 * focalLength)))/lensSqueeze

hyperfocal: ((sensorD/(CoC/unitScale))*(sensorD/fStop) * ((focalLength/sensorD) * (focalLength/sensorD)))/unitScale

depthOfField: (2 * hyperfocal * focusDistance * (focusDistance – (focalLength/unitScale)))/((hyperfocal * hyperfocal) – ((focusDistance – (focalLength/unitScale)) * (focusDistance – (focalLength/unitScale))))

nearFocus: if(focusDistance<focusNearLimit, focusNearLimit, (hyperfocal * focusDistance)/(hyperfocal + focusDistance))

farFocus: if(focusDistance>hyperfocal, hyperfocal*2, (hyperfocal * focusDistance)/(hyperfocal – focusDistance))

Same link at top for text file containing set of expressions to copy/paste.

Action Setup:

AIM node is used to define focus.  Camera will follow it.

External GLSL shader drives camera settings and receives focalDistance from Action AIM object.

Keep a copy in UserBin for easy access. 

If GLSL shader disconnected, expressions are lost, but seems to bake the results into the Action.

Copy/paste expressions from text doc to recreate.

Top View is helpful.  Moving AIM further away will adjust near/far planes.

focalPlanes_CTL axis allows scale on focalPlane reference x, y, z = near, focus, far

Also uses centre.z as general scale of the refGeo which could make more visible in z buffer histo of defocus node of choice.

ref_offset nodes allow to reposition for better view in z buffer. Adjust x/y but z is locked out to zero.

Addtl output set to REF cam which is birdsEye view of scene.

Defocus

You can choose a defocus that will accept Z-depth pass, OFX or Matchbox.

BlurMax is a variable in the GLSL based on relationship of focal length, distance, etc.  Use to link blur of defocus.  Different options for defocus may need an arbitrary multiplier to get desired results.

switch_MASTER flips all the outputs so focal planes can be visible when used in histo for depth. Do NOT animate. All On or All Off.

Duplicate w Connections (CTL+SHIFT+D) to try plug in different defocus options to compare.

SensorSize group

FYI, this contains an action node which uses expression to drive scale of square from GLSL sensorSize inputs

SensorInfo_ burnInMetadata tool. Custom text entry for sensor size

Helpful links:

https://www.yedlin.net/

https://www.arri.com/en/camera-systems/cine-lenses/

https://panalab.panavision.com

Leave a Reply