Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding depth of field with the Bokeh lens shader

From: Lighting and Rendering with mental ray in Maya

Video: Adding depth of field with the Bokeh lens shader

The Bokeh Lens Shader in mental ray is the best way to add depth of field effects or depth of field blurring in a scene, mainly because it's easy to control, and it's actually very efficient. Normally rendering with mental ray, you'll find that in your Camera settings, there are some settings here for depth of field. So these are sort of the native Depth of Field effects. These work pretty well; however, you'll find that if you use the Bokeh Lens Shader instead of using these, you get a better-looking render, and it will also be more efficient.

Adding depth of field with the Bokeh lens shader

The Bokeh Lens Shader in mental ray is the best way to add depth of field effects or depth of field blurring in a scene, mainly because it's easy to control, and it's actually very efficient. Normally rendering with mental ray, you'll find that in your Camera settings, there are some settings here for depth of field. So these are sort of the native Depth of Field effects. These work pretty well; however, you'll find that if you use the Bokeh Lens Shader instead of using these, you get a better-looking render, and it will also be more efficient.

And in this movie, I am just going to describe how to add the shader and why it works better than using these Depth of Field effects. So let's take a look at the render of the scene as it stands right now, without depth of field. So I am just going to create a render from camera1. So here is the scene, and it uses some global illumination, physical light shader on the lamp here. I have a point light behind the camera, which you can see reflected here in these reflective spheres right here, and then just a number of objects that are positioned throughout the scene.

So I will store this image. I have camera1 selected, that's my rendering camera, and I am going to go down to the Lens Shader section, under mental ray, and I am going to click on this checker box next to Lens Shader, pull up the Create Render Node box, and here, under mental ray, I am going to click on Lenses, and I am going to click on mia_lens_bokeh; Bokeh is Japanese for blur, so that's what this means.

So I am going to click on that, and it has added it to the camera. So here are the attributes for the shader itself, mia_lens_bokeh. If you see, if I click on camera1 here, you can see it's connected right there, and I can just click on this Arrow button to switch to the attributes. So I am going to leave the attributes at their default settings and create another test render, so we can see how this looks. So here is the result we get from the render.

You can see that it's taking quite a bit longer, four minutes. Adding depth of field is always going to add a lot to render time, so it's something that you really want to be careful when you add to your scenes. Let's take a look at the render here. You can see that way in the distance here, at the end of the room, it's blurry, but it's more in focus than the objects that are closer to the room. The reason for this is because of the position of the focal plane in our scene. So I would like to show you how you can adjust that. And that's this setting right now.

Currently, it's set to 100. If I switch to the Perspective view, we can see our grid down here, and this is about 10 units. 100 units from the camera is going to be out here somewhere. These parts of the scene are going to be already slightly blurry, and these parts of the scene are going to be very blurry. So to bring these objects into focus, we can start to reduce this value. What I would like to show you is a technique to make this a bit more interactive, because rather than constantly making adjustments to the setting and doing a test render and seeing how it looks, it would be nice if you had some interactive controls so that you could just position something in the scene and know that that part of the scene is going to be in focus.

So I will show you how to set up a custom control for doing just that. I am going to go to the Create menu, and I am going to go Create > Measure tools > Distance tool. So you'll see that the cursor changes to this crosshair, and I am just going to click just randomly, anywhere in the scene; see it's going to create two locators in the scene, and between them I have this little icon, indicating the distance in the tool. So as I move either one of these locators, you'll see the distance increase or decrease.

So this gives me a better way of seeing the distances between objects in the scene. So the first thing I like to do is I am just going to constrain this locator to the camera, so this is always attached to the camera. So to do that, I am going to select camera1 in the Outliner. I am going to Ctrl+Select locator1 in the Outliner. I am going to switch to the Animation menu set, and under Constrain, I am going to use Point. Let me open up the Options here under Point Constraint and make sure that Maintain offset, you want to turn this off.

If this is off, the locator will snap to the position of the camera. So I am going to press Add, and you can see the locator snaps to the position of the camera, and now everywhere I position locator2 in the scene, I can see the distance. So in other words, I know that this sphere is 49 units away from the camera. So now what I can do is I can connect the distance indicator here directly to the Lens Shader, so that I don't have to adjust that slider anymore.

Everywhere I move this locator in here, it will automatically adjust. So in other words, if this distance is connected to the Plane setting here on the Shader, then I know every time I move locator2, wherever I put it in the scene, this Plane setting will update automatically, and I don't have to worry about adjusting that anymore. So to do that, I am just simply going to open up the Hypershade here. It's just one way to make some connections. And in the Work Area, I am just going to drag camera1 over here, select it, and do Graph, Input and Output Connections right here.

And when I do that, I can see, here's my Lens Shader right here. And I am also going to drag the distanceDimension node here from the Outliner. I am going to middle-mouse-button-drag this into the Work Area of the Hypershade. So now what I am going to do is I am just going to middle-mouse-button-drag distanceDimension, choose Other. I want to make sure that I have the Distance setting in here.

I made a very simple and typical mistake. So let me do that again. What I really want to do is I want to make sure that I drag the Shape node of the distanceDimension. So I am going to go Display, make sure that Shapes is on, so I can see Shape nodes, and I am just going to expand this, so I can see, here is the Transform node for distanceDimension1, and here is the Shape node. This is what I actually want to middle- mouse-button-drag into the Work Area. So now that I have that, you can see it's connected to locator2 and locator1. Now I am going to middle-mouse-button- drag distanceDimensionShape1 on top of mia_lens_bokeh, and I'll just choose Other.

When I do that, down here at the bottom, I have Distance, I can click on that to select that, and here on the right side, I'll choose Plane. Now we can see in the Work Area, we have a connection now between distanceDimensionShape node and the MIA Bokeh Lens. If I select the lens, you can see the setting here is 49.270, and this is what this is showing here in the outliner: 49.269; its rounded up for us a little bit.

So now as I move, I want to move this to the position of the Cube here, the setting of 25, and take a look in this tab. We have a setting of 25. So now, let's take a render. Before I do another render, I want to adjust a couple of more settings here. The Radius is going to adjust essentially the blurriness of the scene. So the lower the Radius, the sharper the scenes will be, and by lowering this, I am going to save a little rendering time.

Let me set this down to 0.5, and let's pull up our Render view. I am going to store this image, and create another render. So here's our render, and I've reduced the render time a little bit, and that's mainly by decreasing the Radius setting, because now I have less blurring, so that saved a little bit of render time. So now you can see that the cube is in focus, the stuff in front of the cube, the sphere is out of focus, and the stuff behind the cube is also out of focus. So here is where the plane is in my settings.

So as I move locator2 anywhere in the scene, I know that those objects are going to be in focus, and the rest is going to be blurry. I am going to undo that and go back there. I would like to show you a couple of other settings on the shader that will be very helpful. And switching back on the mia_lens_bokeh tab. The Radius controls the amount of blur. The Sampling controls the quality. You can see that this blur is very grainy here.

By increasing the samples here, I will get higher-quality blur. It will look smoother. It will increase render time a lot. So be careful when increasing that. But the reason that I like this shader, as opposed to the traditional Depth of Field settings there on camera is that this sampling is applied only to the areas that are out of focus in the render. If I was using the traditional Depth of Field, in order to improve the quality, I would have to go to the Render settings, and under Quality tab, I would have to adjust the Min and Max Sampling.

And when I do that, it will improve the blurring, but unlike using the Bokeh shader, it will apply those settings to everything in the scene, which will increase render time even more. So using the Bokeh shader is much more efficient render-wise than using traditional Depth of Field, and that's why I prefer it for creating Depth of Field effects in the camera. To adjust the look of the highlights and other qualities, in other words, the way the blur looks, you can adjust the Bias and the Blade Count and the Blade Angle, and those will change the way that the highlights look, the shape of them, as well as some of the other aspects of the blurring.

But that's the basics for using the Bokeh shader. I think when you're creating in camera Depth of Field effects in your renders, that's definitely the way to go.

Show transcript

This video is part of

Image for Lighting and Rendering with mental ray in Maya
Lighting and Rendering with mental ray in Maya

59 video lessons · 7949 viewers

Eric Keller
Author

 
Expand all | Collapse all
  1. 3m 46s
    1. Welcome
      1m 32s
    2. Using the exercise files
      2m 14s
  2. 19m 8s
    1. What is a CG light?
      1m 22s
    2. Types of CG lights
      10m 55s
    3. Direct lighting
      4m 48s
    4. Indirect lighting
      2m 3s
  3. 53m 20s
    1. Decay rate
      6m 30s
    2. Previewing lighting and shadows
      2m 37s
    3. Creating depth map shadows
      1m 57s
    4. Troubleshooting depth map shadows
      2m 38s
    5. Shadow map overrides
      5m 30s
    6. Using the shadow map camera
      5m 31s
    7. Saving and reusing shadow maps
      2m 48s
    8. Creating raytraced shadows
      1m 56s
    9. Adding softness to raytraced shadows
      3m 42s
    10. Creating area light shadows
      5m 11s
    11. Sample: mental ray area light
      4m 23s
    12. Setting area light visibility
      8m 7s
    13. Creating soft shadows with spot lights
      2m 30s
  4. 43m 35s
    1. Setting global illumination for interiors
      2m 33s
    2. Tuning global illumination
      5m 56s
    3. Global illumination photons
      1m 12s
    4. Activating caustic light effects
      3m 28s
    5. Tuning caustic settings
      3m 35s
    6. Setting caustic light effects on metal
      2m 35s
    7. Using final gathering for indirect lighting
      2m 9s
    8. Tuning final gathering
      4m 2s
    9. Reusing final gathering maps
      3m 21s
    10. Adding light with shaders
      5m 27s
    11. Creating final gathering maps for animation
      4m 26s
    12. Combining final gathering with global illumination
      4m 51s
  5. 1h 2m
    1. Activating the Physical Sun and Sky network
      2m 33s
    2. Tuning the Physical Sun and Sky settings
      7m 18s
    3. Applying physical light shaders
      8m 54s
    4. Applying image-based lighting
      8m 57s
    5. Tone mapping
      6m 23s
    6. Applying portal light shaders
      7m 45s
    7. Creating light beams with participating media
      10m 9s
    8. Adding depth of field with the Bokeh lens shader
      10m 39s
  6. 48m 21s
    1. Introducing render layers
      6m 13s
    2. Creating render layers
      4m 28s
    3. Splitting a scene into render layers
      15m 36s
    4. Applying render layer presets
      7m 47s
    5. Setting render layer overrides
      7m 7s
    6. Creating render layer composites
      3m 52s
    7. Organizing renders with tokens
      3m 18s
  7. 42m 24s
    1. Introducing render passes
      2m 56s
    2. Comparing render passes and render layers
      6m 44s
    3. Editing render passes
      10m 41s
    4. Using appropriate materials
      5m 51s
    5. Batch-rendering passes
      5m 56s
    6. Compositing in After Effects
      6m 41s
    7. Rendering the EXR image format
      3m 35s
  8. 23m 3s
    1. Anti-Aliasing Quality
      6m 44s
    2. Setting color profiles
      2m 53s
    3. Diagnosing raytracing
      5m 7s
    4. Adjusting motion blur
      6m 57s
    5. Finding mental ray help
      1m 22s
  9. 21s
    1. Goodbye
      21s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Lighting and Rendering with mental ray in Maya.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.