## camera lens

Starting easy.
oluf
Posts: 3
Joined: Sun May 26, 2013 9:30 pm

### camera lens

Hi.

I am currently working on a path tracer and got it working pretty well. I however would like to add a realistic camera model to it but am having a bit of trouble finding good articles about it.

I would really appriciate it if any of you could point me towards some good ressources on the subject, I found this: http://graphics.stanford.edu/papers/camera/ and read the paper but am a bit lost on how to get started on the actual implementation of it.

dr_eck
Posts: 45
Joined: Mon Dec 05, 2011 7:35 pm

### Re: camera lens

Ah, someone has stumbled into my area of expertise. (I design lenses for a living.) The first thing to remember is that a really good lens will give you images that look just like a theoretical pinhole camera, but with some depth of field blurring. This means that you can fake a lens pretty easily with well known techniques. If that's not good enough, all you have to do is model a lens with the shapes and proper refractive indices (your tracer does include different refractive indices for different colors, does it not?), and you're good to go. Am I also right in assuming that you know how to handle refraction?

Figure 1 is a good place to start. If your image is 24 x 36 mm, then a 50 mm focal length lens is a "normal" lens - the one that used to be sold with all basic SLR's before zoom became dominant. To get from the numbers in the table to ones for a 50 mm lens, just divide all the radii, thicknesses and apertures by 2.

What I'd do to get started is to define the following surface geometries: a spherical cap, a cylinder and an annulus. To get good results, you'll either need to tessilate these surfaces (at least the spherical caps) very finely or use spheres as primitives. The first lens is defined by two spherical caps connected by a cylinder. The axis of the cylinder is the "optical axis", which is the axis of symmetry for all of the lenses. The second and third lens share a spherical cap surface. (Actually, they are glued together with a very thin layer of glue, but that can be ignored.) The third lens has 4 surfaces: two spherical caps, a cylinder and an annulus.

oluf
Posts: 3
Joined: Sun May 26, 2013 9:30 pm

### Re: camera lens

Hi, thanks a lot for the reply!

I currently have some DOF but what I am after is indeed a modelling of actual lenses.
My current tracer does not include refractive indices for different colors - the way i currently do it is by simply doing refraction based on my PDF for the given material and either trace a ray as diffuse, reflect or refract.

It seems to me from your reply that a first approach would be to model for example a part of a sphere - trace a refraction ray trough it and then trace the resulting ray into my scene?

dr_eck
Posts: 45
Joined: Mon Dec 05, 2011 7:35 pm

### Re: camera lens

It seems to me from your reply that a first approach would be to model for example a part of a sphere - trace a refraction ray trough it and then trace the resulting ray into my scene?

Yes, that will work. If your lens is a sphere on 1 side and a plane on the other, thickest in the middle, then it will work as a lens. The focal length will be
$f=\frac{R}{n-1}$
where R is the radius of the sphere and n is the refractive index. If you put the lens with the curved side toward your image plane, the distance from the lens to the image plane should be equal to the focal length. That's the easy way, but you get sharper images if you turn the lens around and space it from the image plane by a distance given by
$d=f-\frac{t}{n}$
where t is the thickness of the lens (the axial distance from the spherical surface to the plane surface).

(The equations will look pretty as soon as MathJax support is added to the new server. Until then, I hope you can decode them.)

oluf
Posts: 3
Joined: Sun May 26, 2013 9:30 pm

### Re: camera lens

Thanks again - I got a lot more to go on now! (maybe I will return with more questions about this! )