<p>See Kolb, et al., <a href="http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Cameras/Realistic%20Camera%20Model.pdf" rel="nofollow"><em>A Realistic Camera Model for Computer Graphics</em></a>, SIGGRAPH 95.</p>

<p>However, do bear in mind that camera models which mimic real-world cameras aren't necessarily what you want for the rendering phase. In a visual effects/post-production scenario, the more blur/vignetting/distortion that the camera model introduces, the worse it is for the compositor/colour timer. It's often better to do it as a post-pass.</p>

CC BY-SA 3.0
2015-08-17T06:28:22.107Z
2015-08-18T02:02:18.880Z
2015-08-18T02:02:18.880Z
Pseudonym
<p>The next step up from a pinhole camera model is a <a href="https://en.wikipedia.org/wiki/Thin_lens" rel="noreferrer">thin lens</a> model, where we model the lens as being an infinitely thin disc. This is still an idealization that pretty far from modeling a real camera, but it will give you basic depth of field effects.</p>

<p><a href="https://i.sstatic.net/7QOTx.jpg" rel="noreferrer"><img src="https://i.sstatic.net/7QOTx.jpg" alt="Thin lens model"></a></p>

<p>The image above, from <a href="http://www.panohelp.com/thinlensformula.html" rel="noreferrer">panohelp.com</a>, shows the basic idea. For each point on the image, there are multiple rays arriving at that image point, via every point on the 2D lens surface. Therefore, generating an image like this using Monte Carlo will require picking, for each ray, both a 2D sample point on the image plane and an independent 2D sample point on the lens surface.</p>

<p>The user-facing parameters to set will be the lens radius (as a physical radius in scene units), which controls how shallow the focus range is (larger lens = shallower focus range), and the distance at which you want objects to be in focus.</p>

<p>To generate eye rays into the scene, you can calculate the position and direction of rays leaving the lens surface; in this model there's no need to explicitly simulate the image plane and the refraction through the lens.  Basically, think of the lens as centered at the camera position and oriented to face the camera direction.</p>

<p>Based on the image location, construct a ray from the camera position (lens center) into the scene, just as you would in the pinhole model; then find its intersection with the focal plane. That's where all the rays from that image location should converge.  Now you can offset the starting point of the ray to a randomly chosen point on the lens, and set its direction to be toward the convergence point.</p>

<p>You can generalize this a bit by allowing the focal plane to be something other than a plane, or the lens to be something other than a circular disc, and following the same process. That can produce some interesting if not-quite-physical effects.  It's also possible to go beyond this simple model with a more physically realistic simulation of a camera's lens elements&mdash;but that's beyond my expertise.</p>

CC BY-SA 3.0
2015-08-14T21:24:23.393Z
2015-08-14T21:24:23.393Z
Nathan Reed
<p>I have written a small path-tracer after learning and experimenting on <a href="http://www.kevinbeason.com/smallpt/">smallpt</a>.</p>

<p>The only thing that I did not write (and understood) myself is how the initial rays are computed and fired from the camera. I got the principle right, but I'm looking for some resources describing how to:</p>

<ul>
<li>Compute the initial direction of rays</li>
<li>Modelize a real lens (as opposed to pinhole camera), supposedly allowing effects like depth of field ?</li>
</ul>

<p>State of the art maths and physics are not required, but OK if explained thoroughly.</p>

<raytracing><lighting><monte-carlo><physically-based><physics>
How to build a decent lens/camera objective model for path tracing?
teh internets is made of catz
# How to build a decent lens/camera objective model for path tracing?

(Asked by: username_0 on 2015-08-14)

I have written a small path-tracer after learning and experimenting on [smallpt](http://www.kevinbeason.com/smallpt/).

The only thing that I did not write (and understood) myself is how the initial rays are computed and fired from the camera. I got the principle right, but I'm looking for some resources describing how to:

* Compute the initial direction of rays
* Modelize a real lens (as opposed to pinhole camera), supposedly allowing effects like depth of field ?

State of the art maths and physics are not required, but OK if explained thoroughly.

**Tags:** raytracing, lighting, monte-carlo, physically-based, physics


---

## 2 answers

### Answer by username_2 on 2015-08-14. Score: 14 | Accepted answer

The next step up from a pinhole camera model is a [thin lens](https://en.wikipedia.org/wiki/Thin_lens) model, where we model the lens as being an infinitely thin disc. This is still an idealization that pretty far from modeling a real camera, but it will give you basic depth of field effects.

[![Thin lens model](https://i.sstatic.net/7QOTx.jpg)](https://i.sstatic.net/7QOTx.jpg)

The image above, from [panohelp.com](http://www.panohelp.com/thinlensformula.html), shows the basic idea. For each point on the image, there are multiple rays arriving at that image point, via every point on the 2D lens surface. Therefore, generating an image like this using Monte Carlo will require picking, for each ray, both a 2D sample point on the image plane and an independent 2D sample point on the lens surface.

The user-facing parameters to set will be the lens radius (as a physical radius in scene units), which controls how shallow the focus range is (larger lens = shallower focus range), and the distance at which you want objects to be in focus.

To generate eye rays into the scene, you can calculate the position and direction of rays leaving the lens surface; in this model there's no need to explicitly simulate the image plane and the refraction through the lens. Basically, think of the lens as centered at the camera position and oriented to face the camera direction.

Based on the image location, construct a ray from the camera position (lens center) into the scene, just as you would in the pinhole model; then find its intersection with the focal plane. That's where all the rays from that image location should converge. Now you can offset the starting point of the ray to a randomly chosen point on the lens, and set its direction to be toward the convergence point.

You can generalize this a bit by allowing the focal plane to be something other than a plane, or the lens to be something other than a circular disc, and following the same process. That can produce some interesting if not-quite-physical effects. It's also possible to go beyond this simple model with a more physically realistic simulation of a camera's lens elements—but that's beyond my expertise.


---

### Answer by username_1 on 2015-08-17. Score: 4

See Kolb, et al., [*A Realistic Camera Model for Computer Graphics*](http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Cameras/Realistic%20Camera%20Model.pdf), SIGGRAPH 95.

However, do bear in mind that camera models which mimic real-world cameras aren't necessarily what you want for the rendering phase. In a visual effects/post-production scenario, the more blur/vignetting/distortion that the camera model introduces, the worse it is for the compositor/colour timer. It's often better to do it as a post-pass.


---

