|
2164 | 2164 |
|
2165 | 2165 | The reason we defocus blur in real cameras is because they need a big hole (rather than just a
|
2166 | 2166 | pinhole) to gather light. This would defocus everything, but if we stick a lens in the hole, there
|
2167 |
| -will be a certain distance where everything is in focus. The distance to that plane where things are |
2168 |
| -in focus is controlled by the distance between the lens and the film/sensor. That is why you see the |
2169 |
| -lens move relative to the camera when you change what is in focus (that may happen in your phone |
2170 |
| -camera too, but the sensor moves). The “aperture” is a hole to control how big the lens is |
2171 |
| -effectively. For a real camera, if you need more light you make the aperture bigger, and will get |
2172 |
| -more defocus blur. For our virtual camera, we can have a perfect sensor and never need more light, |
2173 |
| -so we only have an aperture when we want defocus blur. |
2174 |
| - |
2175 |
| -A real camera has a compound lens that is complicated. For our code we could simulate the order: |
2176 |
| -sensor, then lens, then aperture, and figure out where to send the rays and flip the image once |
2177 |
| -computed (the image is projected upside down on the film). Graphics people usually use a thin lens |
2178 |
| -approximation. |
| 2167 | +will be a certain distance where everything is in focus. You can think of a lens this way: all light |
| 2168 | +rays coming _from_ a specific point at the focal distance -- and that hit the lens -- will be bent |
| 2169 | +back _to_ a single point on the image sensor. |
| 2170 | + |
| 2171 | +In a physical camera, the distance to that plane where things are in focus is controlled by the |
| 2172 | +distance between the lens and the film/sensor. That is why you see the lens move relative to the |
| 2173 | +camera when you change what is in focus (that may happen in your phone camera too, but the sensor |
| 2174 | +moves). The “aperture” is a hole to control how big the lens is effectively. For a real camera, if |
| 2175 | +you need more light you make the aperture bigger, and will get more defocus blur. For our virtual |
| 2176 | +camera, we can have a perfect sensor and never need more light, so we only have an aperture when we |
| 2177 | +want defocus blur. |
| 2178 | + |
| 2179 | +<div class="together"> |
| 2180 | +A real camera has a complicated compound lens. For our code we could simulate the order: sensor, |
| 2181 | +then lens, then aperture, and figure out where to send the rays and flip the image once computed |
| 2182 | +(the image is projected upside down on the film). Graphics people usually use a thin lens |
| 2183 | +approximation: |
2179 | 2184 |
|
2180 | 2185 | ![Figure [cam-lens]: Camera lens model](../images/fig.cam-lens.jpg)
|
2181 | 2186 |
|
2182 |
| -We also don’t need to simulate any of the inside of the camera. For the purposes of rendering an |
2183 |
| -image outside the camera, that would be unnecessary complexity. Instead I usually start rays from |
2184 |
| -the surface of the lens, and send them toward a virtual film plane, by finding the projection of the |
| 2187 | +</div> |
| 2188 | + |
| 2189 | +<div class="together"> |
| 2190 | +We don’t need to simulate any of the inside of the camera. For the purposes of rendering an image |
| 2191 | +outside the camera, that would be unnecessary complexity. Instead, I usually start rays from the |
| 2192 | +surface of the lens, and send them toward a virtual film plane, by finding the projection of the |
2185 | 2193 | film on the plane that is in focus (at the distance `focus_dist`).
|
2186 | 2194 |
|
2187 | 2195 | ![Figure [cam-film-plane]: Camera focus plane](../images/fig.cam-film-plane.jpg)
|
2188 | 2196 |
|
2189 |
| -<div class='together'> |
2190 |
| -For that we just need to have the ray origins be on a disk around `lookfrom` rather than from a |
2191 |
| -point: |
| 2197 | +</div> |
| 2198 | + |
| 2199 | +Normally, all scene rays originate from the `lookfrom` point. In order to accomplish defocus blur, |
| 2200 | +generate random scene rays originating from inside a disk centered at the `lookfrom` point. The |
| 2201 | +larger the radius, the greater the defocus blur. You can think of our original camera as having a |
| 2202 | +defocus disk of radius zero (no blur at all), so all rays originated at the disk center |
| 2203 | +(`lookfrom`). |
2192 | 2204 |
|
2193 | 2205 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2194 | 2206 | vec3 random_in_unit_disk() {
|
|
2198 | 2210 | } while (dot(p,p) >= 1.0);
|
2199 | 2211 | return p;
|
2200 | 2212 | }
|
| 2213 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2214 | + [Listing [rand-in-unit-disk]: <kbd>[vec3.h]</kbd> Generate random point inside unit disk] |
2201 | 2215 |
|
| 2216 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2202 | 2217 | class camera {
|
2203 | 2218 | public:
|
2204 | 2219 | camera(
|
|
2253 | 2268 | };
|
2254 | 2269 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2255 | 2270 | [Listing [camera-dof]: <kbd>[camera.h]</kbd> Camera with adjustable depth-of-field (dof)]
|
2256 |
| -</div> |
2257 | 2271 |
|
2258 | 2272 | <div class='together'>
|
2259 | 2273 | Using a big aperture:
|
|
0 commit comments