Bokeh Lens Shader – Closer look – Tutorial

Bokeh is a Japanese word for “blurred or fuzzy” (暈け)
This is a real life phenomenon that occurs in photography where the light sources in an out of focus area of an image.  Different lens Bokeh produces different aesthetic qualities in out of focus backgrounds, which are often used to reduce distractions and emphasize the primary subject.  For some real life examples,  please visit the Bokeh page on the Wikipedia.
We can simulate the same effect in Maya using the Bokeh Lens Shader in mental ray.

bokeh example

We can simulate the same effect in Maya using the Bokeh Lens Shader in mental ray.

mental ray DOF

This is the render without using Bokeh as our starting point.

no depth of field

We start by selecting the camera of choice, and under the attribute editor of that camera, mental ray > Lens Shader.

Note: you can also expand the Lens Shader section and add it in there as well.
mental ray camera setup

Locate the Mia_lens_bokeh Shader under the mental ray tab > Lenses

Mia lens Bokeh

By default the render will look something like this

defualt render

Note: The Shader parameters rely on the scene size, therefore results will vary from one file to the other.

mia lens Bokeh attr

This is a toggle on/off switch to disable the Shader if needed. Default is on.

Is the distance to the focal plane from the camera, i.e. the point of interest.
This point will be in focus and the rest will be out of focus.
To get the proper Plane value, we will use the measuring tool to give us that distance from the camera to the point of interest.

distance tool

mental ray Bokeh
Plane value = 18.8

mental ray Bokeh
Plane value = 8.7

This is the radius of confusion. This is an actual measurement in scene units.
A value of 0 will result with No Bokeh. The higher the value, the further away the Blur will accrue.

bokeh radius

The more samples we have the better the quality of the “blur”, however that comes with the expense of render time.

bokeh samples

Lower values push the sample probability towards the center, creating a “softer” looking DOF effect with a more “misty” look.
Higher values push the sample probability towards the edge, creating a “harder” looking DOF where bright spots actually resolve as small circles.

bokeh bias

Blade Count:
This defines how many “edges” the “circle” of confusion has. A zero value makes it a perfect circle. Notice the shape of the highlight in the blurred area of the rendered image.
bokeh blade count
Bias = 0 notice how the blurred highlights are perfect circle.

bokeh blade
Bias = 4 notice the 4 corners in the blurred highlights.

Blade Angle:
One can also set the angle with the blade_angle parameter, which is expressed such that 0.0 is zero degrees and 1.0 is 360 degrees.
This will be more notable when you have hard corner highlight (value 4 for example)

bokeh blade angle
Blade Angle = 0

Blade Angle = 0.25 (90 degree) notice how the diamond shape highlights looks more like a square.

Use Bokeh:
This option will allow us to use an image as a specific Bokeh map.
When this option is used, the parameters “bias”, “blade count” and “blade angle” have no effect.

The map defines the shape of the DOF filter kernel, so a filled white circle on a black background is equivalent to the standard blur. Generally, one need more samples to accurately “resolve” a custom Bokeh map.
Note: The size of this image map does not contribute to the quality of the render.

Sample renders with Different Bokeh images.




The tutorial can be found as a pdf here

Recent Entries

10 Responses to “Bokeh Lens Shader – Closer look – Tutorial”

  1. oren Says:

    really useful tutorial!!! thx!!!

  2. Kap13 Says:

    How do you get a larger area of focus? I cannot get the closest parts and farthest parts of an object in focus.

  3. Ashraf Says:

    it’s based on the camera distance from the object

  4. arnel Says:

    this is good but this would be soooo simple to just do in photoshop or AE

  5. Shashank Says:

    Great tutorial…..
    thanks a lot.Was struggling will DOF for a while until I found this

  6. Govind Says:

    @ Arnel, Yes is much simpler and faster to do so in post, however the DOF we gain by following this tutorial will be a actual 3d DOF.

  7. cox Says:

    You cannot have a correct DOF in post. Most of the time a 2D DOF is working, but to make a realistic one you need the information that are behind the objects. The blur of the DOF is a IN and OUT blur that why in 2D you cannot have the IN blur because you don’t have the pixel information. The solution would be to separate in layer to allow you recreating the most correct DOF.

  8. alex Says:

    Hi !

    I want to say that i’ve found that the plane parameter don’t work with the distance tool always.It never worked for me…I’ve always found the values with trial & error.As for the iris radius formula from documentation (focal_length / f_number) / 2, i found that it gives very close values.

  9. alex Says:

    I forgot to mention that i might have used a different focal lenght and f-stop, 65 and 11 for example, and after inserting the default values of 35 and 5.6, the bokeh isn’t working with distance tool anymore.And it is nasty, since there are a few cases where a focal lenght of 35 is needed.Any advice for this? Maybe a zoom formula?

  10. Graham Says:

    Hi – I had alot of trouble recently with flickering text in my renders of a magazine.

    I thought it was the Final Gather but think now it couldd possibly be the bokeh settings.

    My samples were at 8. Would this be the cause of flickering of text as the camera moves across the pages?


Leave a Reply