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