<p>First we can calculate the physical diameter of CoC in the image plane, given the lens parameters. This equation is from <a href="https://en.wikipedia.org/wiki/Circle_of_confusion#Determining_a_circle_of_confusion_diameter_from_the_object_field" rel="nofollow noreferrer">Wikipedia – Circle of confusion</a>:
$$
c = {|S_2 - S_1| \over S_2} {f^2 \over N(S_1 - f)}
$$
where the variables are:</p>

<ul>
<li>$c$: the physical CoC diameter in the image plane</li>
<li>$S_1$: focal distance (the distance at which a subject would be in perfect focus)</li>
<li>$S_2$: actual distance to the subject (the point whose CoC we are calculating)</li>
<li>$f$: the focal length of the lens</li>
<li>$N$: the f-number at which the lens aperture is set.</li>
</ul>

<p>Then, divide this CoC diameter by the film or sensor frame size to get the blur diameter in texture coordinates. You can additionally multiply it by your rendering resolution to get the blur diameter in pixels if desired.</p>

<p>As an example calculation, suppose we render a 1920×1080 image, as if through a 85mm lens at f/1.4, on a 35mm camera (frame size 36×24 mm), and focused at 3m while our subject is 5m away. Then we can calculate:
$$
{|5\text{m} - 3\text{m}| \over 5\text{m}} {(85\text{mm})^2 \over 1.4(3\text{m} - 85\text{mm})} {1920\text{px} \over 36\text{mm}}
$$
(Don't forget to convert units, since we are mixing meters and millimeters here!) I get a blur diameter of ~38 px, so the radius would therefore be ~19 px.</p>

CC BY-SA 4.0
2018-08-07T09:32:18.720Z
I almost get the same result, but even with Wolfram Alpha I get 37.77 pixels, and 0.7082 mm with your example. Also, when using focal length in millimetres, a huge scaling occurs as the focal plane in metres reaches it.
When graphed as such, https://www.desmos.com/calculator/mlblfdvknw, it's noticeable. Is there a way to convert the units properly?
SgerbwdGwyn
CC BY-SA 4.0
2018-08-07T18:50:21.510Z
Sorry, I should've been more explicit. One way to do it is to convert all the millimeters to meters by dividing by 1000. Be sure you do that _before_ squaring or any other operation. You're right about the 37.77, I must have typo'd it when I did the calculation initially.
Nathan Reed
CC BY-SA 4.0
2018-08-07T18:59:55.037Z
And here's an updated version of your graph with the conversions: https://www.desmos.com/calculator/j2gcokbykz
Nathan Reed
CC BY-SA 4.0
2018-08-08T21:00:31.167Z
Many thanks! I was going from M to MM but I hadn't adjusted the scales properly
SgerbwdGwyn
CC BY-SA 4.0
2018-08-05T05:39:22.830Z
2018-08-07T18:52:01.080Z
2018-08-07T18:52:01.080Z
Nathan Reed
<p>Looking at the Wikipedia page for Circle of Confusion, and at such posts as <a href="https://photo.stackexchange.com/questions/24826/is-there-a-formula-to-calculate-dof">this one</a>, I completely understand how to calculate the values for near, far, focal planes and hyperfocal distance. I am also aware of the Zeiss formula for my desired format.</p>

<p><strong>What I'm trying to find out is how to take real camera parameters (focal distance, aperture, focal length) and get a <em>blur radius</em> or similar usable value to configure a blur with them.</strong></p>

<p>Currently, I'm simply using this function:</p>

<pre><code>float getBlurSize(float depth, float focusPoint, float focusScale) {
    float coc = clamp((1.0 / focusPoint - 1.0 / depth)*focusScale, -1.0, 1.0);
    return abs(coc) * MAX_BLUR_SIZE;
}
</code></pre>

<p>All real-world inputs are available to the shader - Aperture f-Number, focal distance, format dimensions (35mm in this case), maximum acceptable CoC from the Zeiss formula, focal length etc., as well as depth and colour. Currently, I am applying the calculations and blur in post.</p>

<blur><camera><post-processing><depth-of-field>
Deriving blur from real optical formulae
SgerbwdGwyn
# Deriving blur from real optical formulae

(Asked by: username_0 on 2018-07-28)

Looking at the Wikipedia page for Circle of Confusion, and at such posts as [this one](https://photo.stackexchange.com/questions/24826/is-there-a-formula-to-calculate-dof), I completely understand how to calculate the values for near, far, focal planes and hyperfocal distance. I am also aware of the Zeiss formula for my desired format.

**What I'm trying to find out is how to take real camera parameters (focal distance, aperture, focal length) and get a *blur radius* or similar usable value to configure a blur with them.**

Currently, I'm simply using this function:

```
float getBlurSize(float depth, float focusPoint, float focusScale) {
    float coc = clamp((1.0 / focusPoint - 1.0 / depth)*focusScale, -1.0, 1.0);
    return abs(coc) * MAX_BLUR_SIZE;
}

```

All real-world inputs are available to the shader - Aperture f-Number, focal distance, format dimensions (35mm in this case), maximum acceptable CoC from the Zeiss formula, focal length etc., as well as depth and colour. Currently, I am applying the calculations and blur in post.

**Tags:** blur, camera, post-processing, depth-of-field


---

## 1 answers

### Answer by username_1 on 2018-08-05. Score: 3 | Accepted answer

First we can calculate the physical diameter of CoC in the image plane, given the lens parameters. This equation is from [Wikipedia – Circle of confusion](https://en.wikipedia.org/wiki/Circle_of_confusion#Determining_a_circle_of_confusion_diameter_from_the_object_field):
$$
c = {|S\_2 - S\_1| \over S\_2} {f^2 \over N(S\_1 - f)}
$$
where the variables are:

* $c$: the physical CoC diameter in the image plane
* $S\_1$: focal distance (the distance at which a subject would be in perfect focus)
* $S\_2$: actual distance to the subject (the point whose CoC we are calculating)
* $f$: the focal length of the lens
* $N$: the f-number at which the lens aperture is set.

Then, divide this CoC diameter by the film or sensor frame size to get the blur diameter in texture coordinates. You can additionally multiply it by your rendering resolution to get the blur diameter in pixels if desired.

As an example calculation, suppose we render a 1920×1080 image, as if through a 85mm lens at f/1.4, on a 35mm camera (frame size 36×24 mm), and focused at 3m while our subject is 5m away. Then we can calculate:
$$
{|5\text{m} - 3\text{m}| \over 5\text{m}} {(85\text{mm})^2 \over 1.4(3\text{m} - 85\text{mm})} {1920\text{px} \over 36\text{mm}}
$$
(Don't forget to convert units, since we are mixing meters and millimeters here!) I get a blur diameter of ~38 px, so the radius would therefore be ~19 px.

> **Comments:**
> **username_0**: I almost get the same result, but even with Wolfram Alpha I get 37.77 pixels, and 0.7082 mm with your example. Also, when using focal length in millimetres, a huge scaling occurs as the focal plane in metres reaches it. When graphed as such, https://www.desmos.com/calculator/mlblfdvknw, it's noticeable. Is there a way to convert the units properly?  
> **username_1**: Sorry, I should've been more explicit. One way to do it is to convert all the millimeters to meters by dividing by 1000. Be sure you do that _before_ squaring or any other operation. You're right about the 37.77, I must have typo'd it when I did the calculation initially.  
> **username_1**: And here's an updated version of your graph with the conversions: https://www.desmos.com/calculator/j2gcokbykz  
> **username_0**: Many thanks! I was going from M to MM but I hadn't adjusted the scales properly  

---

