Search Unity

More realistic depth of field image effect with varying blur.

Discussion in 'Scripting' started by The-Scripter, Mar 23, 2011.

  1. The-Scripter

    The-Scripter

    Joined:
    Nov 10, 2009
    Posts:
    30
    I believe we should be able to improve some of the image effects, including Depth of Field, by varying the amount of blur over parts of the image. The Depth of Field effects seem to create a blurred copy of the image, and use the depth map to fade it out. The radius of the blur remains constant, which is not how depth of field works. Creating a single blurred image with the radius of the blur adjusted based on the depth (or any parameter) would be much more realistic and effective.

    The blurring seems to be done in the script, which accesses the renderTexture multiple times and offsets them on top of each other. Is it possible to base the blur radius on depth or a given map, probably by blurring the image in the shader?

    If some unity users or developers are familiar with the blur effects (the older version is much simpler) or shaderlab in general, do you know how we can adjust the radius of blur this way?
     
  2. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Photoshop has "lens blur" which essentially does exactly what you are talking about and takes a depth mask... and to process a 1280x800 image it takes a few seconds.... On the other-hand an inexpensive box-blur (probably how Unity does it, I don't have pro so I've never seen it) takes a fraction of that amount of time, meaning it's feasible to do it every-frame

    Still it could be possible to have like 4 different cameras rendering different depths of the scene, all of which have different levels of depth blur on them. I say it "could" be possible because I have no idea when the blur is applied in the rendering pipeline.