Adding depth of field
Video: Adding depth of fieldDepth of field is one of those effects that really can add some visual subtlety, power to your images. Sunbeams are neat and they're really cool to see coming in through windows. An ambient inclusion really adds the gravity. But putting depth of field on, really takes the player from seeing something that's not quite right to really sitting in the scene. Here is why, we see with our two eyes or occasionally one. Out to one point in space. And things beyond that, things in the background and things closer than that in the foreground, blur out.
- Next steps
Viewers: in countries Watching now:
Interested in game making? Start in Unity—a game engine for mobile and desktop games and real-time simulations. Author Adam Crespi shows techniques used in game development with Unity and introduces the basics of scripting and game functionality. First, learn how to import models and textures, organize your project and hierarchies, and add terrain, water, and foliage. Next, Adam explores how to use lighting to bring the game to life, and add rendering, particles, and interactivity. The end result is a sample game with a lush environment, fully animated characters, and some basic interactive gameplay.
- Designing the game
- Creating and transforming objects
- Importing and configuring models and textures
- Setting properties in the Inspector
- Creating the terrain geometry
- Building materials and adding shaders
- Creating GameObjects
- Exploring physics
- Animating objects
- Lighting the scene
- Creating 2D game elements
- Adding special effects
Adding depth of field
Depth of field is one of those effects that really can add some visual subtlety, power to your images. Sunbeams are neat and they're really cool to see coming in through windows. An ambient inclusion really adds the gravity. But putting depth of field on, really takes the player from seeing something that's not quite right to really sitting in the scene. Here is why, we see with our two eyes or occasionally one. Out to one point in space. And things beyond that, things in the background and things closer than that in the foreground, blur out.
Cameras see the same way. What this means is that when we see a scene like this in Unity where everything is well, smaller in distance but perfectly in focus, it seems a little bit odd. So we can add on some depth or field to tell the audience, I want you to focus in this range. There's two different depth of field image effects we can put on. And I'll go through a little bit of each one, to show what they do. You can choose which one you want to use depending on the look you want. I'll start out by selecting my main camera in the first person controller and dragging over depth of field 3.4.
I'll roll up the screen's base occlusion and pull that in. What this does is say, here's a focal distance and a focal size, and how much blur we have. I'll try it out just at the default settings. And these are going to need some tweaking already, I can tell you. It's beautiful. Apparently, we forgot our glasses today. Because everything is strongly out of focus. Here's what's really going on, joking aside. The focal distance in depth of field is set to one. One meter out is in focus.
Focal size of zero means that 1.1 meter out is in focus and everything else blurs out from there. Theoretical depth of field is zero. Only one point is in focus at a time, but we use focal size to give us a focal plane thickness, is how you can think of it, a zone of focus instead of a point. So that things more or less stay in focus until they really start to go out. I'll push out that focal distance to 15 and bring up that focal size to six. Next, I'll take that Blur Spread way down.
Here it is at 0.25 and I'll take the blurriness down as well. This way, I've pushed out how far we can see, and given us quite a good zone that's always in focus. I've reduced the maximum blur way down. And this way, things aren't subtly blurry in the deep background. Lastly, I'll look at the quality. Right now, the resolution is low, and I'll see if I can get by with it low because high takes more computing power. There's also a quality choice, only background, or background and foreground.
This is a judgement call on the look. If we're using only background, everything in the foreground up to that focal distance is clear and beyond it we start to see blur. With background and foreground on, the foreground blurs as well. Comes into focus. And then we get the background blur. I'll try it on these settings before I switch over and see if I have enough in focus. This is somewhat better. The building across the way is noticeably blurry still. But inside my building I am definitely in focus. It looks good, although my sky is definitely blurring out.
Inside though, everything is nicely in focus, so I'm really telling the audience, you should run around this building and look around what's in here first before you get outside. Once you get close enough to the outside, things will resolve into focus like as you look through the windows, and you can say, hm, maybe I should go look over there, now that I can see what it is. Here's what happens when we turn on foreground and background. We've got a foreground size now, and we'll really start to see things blur out in the foreground at this value. With the foreground and background blur on, we can definitely see where that focal point is.
If I pull back and look into this space, we can see two walls back are in focus, but the emmas are definitely blurred. Its okay to use this because it can give you a very soft, almost dreamy quality. Just be mindful of using too much blur in there. Too much blur is visually disconcerting. It makes us feel like our eyes aren't working well. I'll take that foreground size back to 0.15, again keeping it very subtle. Now I've got just a little blur in the foreground pushing my attention out to where my focal point is.
In this case, it's really up to you. Which one you want to have your audience focus on. If they're back here knocking over the art, that should probably be in focus. So, in this particular case, most likely a foreground blur is not the right choice. I'll switch back to only background. One of the last things we've got here is, enable Bokeh blur. What this does is enable an extreme blur, and we can see it when we turn it on and scroll down. Bokeh blur is when things like specular highlights, or little twinkling lights, blur out into distinct shapes.
Often we see hexagons or pentagons of light, maybe squares and it really depends on the number of blades in the lens. We can customize that Bokeh blur if we need through the texture mask. Taking in a texture with an alpha channel. You can even make a Bokeh blur turn into hearts or stars if you wanted. What this will do for us then is say, at what point do we see a Bokeh blur, what shape does it become and how big should those pieces be. I'll try it out and see if we notice any difference. At the moment there is not much of a difference and this is because I don't have many round things in here which twinkling highlights.
It is also day light. So I'm not getting any really hidden lights in places. What would be great for a Bokeh blur is if it was near dusk, and there was a sparking fountain in the background, or something similar. Something with little points of light that could bloom into those shapes. So I'll turn off the Bokeh blur, and let my depth of field go, just background only. Now I'll turn off this depth of field, and put on the other depth of field for scatter. I'll drag it in. And now I've got slightly different parameters. First, we've got a focal distance and a focal size.
Then there's a focus on a distinct transform. If we want to keep one object in focus. And finally an aperture. The lower the aperture the blurrier things get. We have a de-focus type depending on what kind of blur we'd like. Both disk blur and DirectX 11 if you're supporting it. And then a sample count and a max blur distance. I'll try this out and see how it looks at the default settings before I adjust it. This is a pretty nice looking blur. Although it's a little blurry on the emmas. They do come in to focus decently when I'm close but it's a little too much blur, as we saw before.
What I'll do is take that focal size up I'll put at four so I'm dealing in a good range and focus and then lower down the aperture to eight. I'll press Play again and now I've got most everything clear and just a little bit of blur in the background. I like the way it's looking although the emmas up close are still very blurred. We actually need to back off to see them in focus. It's up to you, which way you'd like to handle it. Personally, I would like to have this game be about a close focus, because right now, close-up on the art, we're losing the detail in the texture that we should probably see.
So I'd like to use the other depth of field and push that focus back. So it's really a background blur, more than an obscuring blur in the foreground. As with any effect, it's up to you which one you'd like to lose. And you need to pick the one that really enhances the look, feel, mood and immersion of your game. How should the viewer feel when they see this space. Visualize then, for us, enables visualization when we play our game. We'll actually see, what's close and what's far.
And, in this case, we're seeing where that depth of field sits. It's very, very close, and we're seeing what's only in focus. Degenerating into blur very quickly. As we start to push those focal distances around, we'll see that turn into more of a grey scale. And it's a tool for visualizing how far out the blur is, and how subtle it's getting. I'm going to remove this component. And turn back on the depth of field 3.4. I'm ready to add on some final polish. I've got depth of field on, sun shafts, and screens base seclusion.
Things that are naturally occurring and really help bring out the look. Now I can think about unifying the look of my entire scene with some color correction and a little bit of motion blur.
There are currently no FAQs about Unity 4.3 Essential Training.