Optical Vignetting and Depth of Field light distribution
Needs RevisionPublic

Authored by Jan Scheffczyk (Knork) on Nov 19 2017, 3:46 PM.

Details

Summary

What is the feature?

This feature enables the user to alter the shape and the light distribution of the depth of field (bokeh).
To create images like these with a cycles:

Image

What was changed?

Most significant changes are in the way the lens samples are placed onto the lens. Before they where either projected into a disk by concentric_sample_disk or into a regular polygon.
I introduced a third possibility to place them in the intersection of two disk which model from the film-plane visible view into the scene.

For more information please refer to https://knork.org/realistic-bokeh.html or just ask me.

To allow light-distribution a simple weight function that operates on the “radius” of the sample-point was introduced. Similar a distance from center of out shape is defined for a regular polygon and the optical vignetting which allows us to use the same weight function for all cases. The weight function also ensures that the total amount of light passing through the bokeh shape is not altered.

Are there any downsides?

I use rejection sampling for optical vignetting which is physically plausible as light rays are actually being blocked by the lens housing. However this of course means that in focus images will have a vignetting effect and also be noisier on the outside as there are fewer samples passing through the lens.

If anyone knows how to uniformly sample the intersection of two disks please let me know.

Update: I thought it might be useful to provide my test-scene as well

Diff Detail

Repository
rC Cycles
Jan Scheffczyk (Knork) edited the summary of this revision. (Show Details)Nov 19 2017, 3:49 PM
Jan Scheffczyk (Knork) edited the summary of this revision. (Show Details)Nov 20 2017, 10:51 AM

Thanks for the patch.

I won't have time to review this for a bit, but I think it would be important to avoid rejection sampling here. If we throw away a random subset of samples at this stage it's going to increase noise quite significantly.

The most general solution would be to render a small 2D image with the shape, and then importance sample that. We have importance sampling code like that for the background. It would also make it possible to load arbitrary images eventually. There may be a way to importance sample the shape here directly, but I haven't looked into it.

I agree with the general consensus that rejection sampling is probably not the best solution here. I currently working on a solution however it will be fairly expensive compared to rejection sampling or the concentric disk function.
If anyone is interested he can follow along here:
https://stackoverflow.com/questions/47496898/uniform-sampling-of-intersection-area-of-two-disks

Sergey Sharybin (sergey) requested changes to this revision.Dec 6 2017, 3:18 PM

@Brecht Van Lommel (brecht), the image used for bokeh figure might be dependent on the screen space, not sure how one could p[re-calculate CDF in that case. It would have been fine if image was only scaling up and down, but there are more transform being applied, for which i'm not sure how we can map CDF. If there is a trick, i'd really want to know it :)

@Jan Scheffczyk (Knork), afraid we can not have rejection sampling in master, this will become an issue in production files really quick. Maybe it's ok-ish, but only after all other [possibilities are studied.

This revision now requires changes to proceed.Dec 6 2017, 3:18 PM