Depth of field simulator
翻译准备中
设计TypeScript · CSSGitHub @jherr自行安装运营者未确认
试用过了吗? 点一下就好,无需登录。
尚未检测到更新。GitHub 发布版本后会显示在这里。
个人 GitHub 账号下公开仓库的所有者可以登录并验证所有权,自行管理介绍,无需管理员批准。
登录并生成验证文件,在 30 分钟内将其提交到此仓库的默认分支。其他分支或分叉仓库中的文件无效。然后在下方检查文件,即可无需管理员批准直接管理项目。请保留文件以维持管理权限。
如需登录,将前往登录页面。登录后请回到此处,再次点击所选的验证按钮。
安装型项目无需部署域名也可验证。个人仓库可通过 GitHub 登录验证,组织仓库可使用上方的仓库验证文件。
制作者的介绍仅有上面的一句话。 更多详情请阅读仓库 README。 仓库 README ↗
正在加载完整 README。
查看完整 README ↗A web application that allows you to figure out the depth of field of a camera lens. You can adjust the aperture, focal length, and distance to the subject to see how the depth of field changes. The application also shows the hyperfocal distance and the near and far limits of the depth of field. Live Demo
Built with React, TypeScript, Vite, and Chakra UI.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
npm install
npm run dev
Vite prints a local URL (default http://localhost:5173). Open it in a browser; edits hot-reload automatically.
npm run build
The optimized output is written to dist/. Preview the production build with:
npm run preview
| Command | What it does |
|---|---|
npm run dev | Start the Vite dev server with hot reload |
npm run build | Type-check (tsc) and build to dist/ |
npm run preview | Serve the production build locally |
npm run lint | Run ESLint over the ts/tsx sources |
npm test | Run the unit tests (tsx --test) |
All optics are computed in src/App.tsx from four inputs — focal length (f, mm), aperture (N, the f-number), subject distance (s), and the selected sensor — plus a circle of confusion derived from that sensor. Distances are tracked internally in millimeters and converted to feet/inches or centimeters for display (src/utils/units.ts).
The circle of confusion is the largest blur spot that still looks "in focus" to the viewer at normal viewing size. It scales with the sensor: a larger sensor tolerates a larger blur circle because the image is enlarged less to reach final viewing size.
Each preset sensor ships with a fixed CoC (in mm), e.g. 0.029 mm for 35mm full frame and 0.019 mm for APS-C. For a Custom sensor the CoC is estimated from the sensor diagonal:
CoC = √(width² + height²) / 1500
This is the common "diagonal ÷ 1500" rule of thumb (the full-frame diagonal of ~43.3 mm gives ~0.029 mm, matching the full-frame preset).
The crop factor compares a sensor's diagonal to the 35mm full-frame diagonal (≈ 43.27 mm). For a custom sensor:
cropFactor = 43.27 / √(width² + height²)
Preset sensors carry their own crop factor. The 35mm-equivalent focal length (shown for non-full-frame sensors) is simply:
equivalentFocalLength = focalLength × cropFactor
The hyperfocal distance H is the focus distance at which everything from half that distance out to infinity is acceptably sharp. It is computed as:
H = f + f² / (N × CoC)
where f is focal length, N is the f-number (aperture), and CoC is the circle of confusion — all in millimeters.
Given the hyperfocal distance H, the subject distance s, and focal length f, the near and far sharp limits are:
near = (H × s) / (H + (s − f))
far = (H × s) / (H − (s − f))
far − near.The Set Hyperfocal button focuses the subject exactly at H, the setting that maximizes depth of field for the current lens and aperture.
The vertical angle of view comes from the sensor height and focal length:
FoV = 2 × atan( sensorHeight / (2 × f) ) // converted to degrees
This drives how wide the cone is drawn in the scene diagram.
Stopping the aperture down (large f-number) eventually softens the image because the Airy diffraction disk grows larger than the circle of confusion. The Airy disk diameter is approximated as 0.001342 × N mm, so the aperture at which diffraction begins to matter is:
diffractionLimitFStop = CoC / 0.001342
Above this f-number a warning badge is shown. Because the threshold scales with CoC, smaller sensors hit diffraction at wider apertures than larger ones.
Internally everything is inches/millimeters; src/utils/units.ts formats the output:
12 in = 1 ft)1 in = 2.54 cm)These formulas use the standard thin-lens depth-of-field model. They are excellent for understanding and comparing setups, but real lenses (breathing, pupil magnification, etc.) can differ slightly from the idealized math.
src/
App.tsx # Inputs, state, and all DoF/CoC/hyperfocal math
PhotographyGraphic.tsx # The scene diagram (subject, focus cone, limits)
selectStyles.ts # Theme-aware styling for native selects
utils/units.ts # Imperial/metric formatting
assets/ # Lens illustrations
Issues and pull requests are welcome at github.com/jherr/depth-of-field. Please run npm run lint and npm test before opening a PR.
MIT © Jack Herrington