Search Unity

How does Standard Assets Depth of Field work?

Discussion in 'Scripting' started by LeftyTwoGuns, Mar 21, 2015.

  1. LeftyTwoGuns

    LeftyTwoGuns

    Joined:
    Jan 3, 2013
    Posts:
    260
    The manual doesn't explain how to use it very well, at least I don't understand what the terms mean.

    No matter how I mess with the settings, it's always blurry close range and long range, and clear as you get closer to things. That to me isn't very realistic, it just makes everything look blurry. Things two feet from my face aren't blurry until I walk up to them.

    How do I set this to only blur out long distance objects, and leave everything within a certain distance of the main first-person camera unblurred? There doesn't seem to be a setting specifically for that
     
  2. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hi there, in order to understand how Depth of Field works you need basic understanding of optics or at least photography. DoF litteraly refers to the "depth" or distance that contains the clear area of your image. Anything outside that range will be blurred (by it's distance to the edges of the field)

    So from here on depth refers to the size of the field, and field refers to the area that appears clear in the image.

    There are 3 factors that influence the depth, or the size of the field.

    First is the distance between your lens and your subject. The further it is the larger your field will be.
    Second is the focal length (in camera terms this is the amount of "zoom") the more zoomed in you are the smaller your depth of field becomes.
    Third is the aperture, that is the amount of light that is coming through your lens. The more light comes in, the smaller your depth of field is. You can actually see this effect with your own eyes on a bright summer day, sometimes you'll have problems focusing on something and you'll squint your eyes. By doing so you're limiting the amount of light that comes in, therefore increasing your depth of field and able to put whatever you were looking at in focus.

    Now in unity you'll be working with these values but they're simulated, when you're decreasing the focal length you're not actually zooming in but it will decrease the field size as if you were. Same thing with the others, you have to balance all three to get the proper look for what you're looking for.

    Keep in mind, Depth of Field is meant to simulate as if you were looking through a camera, it's not meant to be realistic per say. Things will always be blurry at close range because every lens has a minimum distance before it can focus. I might be wrong but I don't think there's a way to avoid the close range blur.

    A good way to test the different settings is moving your camera somewhere you have something at close range, something you want to focus on and some backdrop then with your camera selected tick the visualize box to get the depth texture. Everything in black will be in focus, everything in white will be out of focus.

    Hope this helps!
     
  3. LeftyTwoGuns

    LeftyTwoGuns

    Joined:
    Jan 3, 2013
    Posts:
    260
    Thank you! That explanation does help and I didn't know about the Visualize option. I'll spend some more time with it. I was looking at it the wrong way