Depth of Field and Resolution

Hello, I have a depth of field post-processing effect on my camera, and it works just like how it should. The problem is that when I change the screen resolution in the gameview, the effect gets weaker. I cannot create a script that increases the strenght of the blur based on resolution, since the effect is already at maximum strength. Does somebody know if there’s a workaround for this?

Shaders have some limits to their versatility. In this case, the question is:

How many loops should the Depth of Field shader make to gather pixel color data for blurring?

The number of passes it makes dictates how far away from the “current” pixel the blur effect reaches to sample new color data. The resolution of the render, by extension, influences what color will be grabbed by each of those samples.

More importantly, as a general rule, the number of loops made for a blur effect in a shader can’t and/or shouldn’t be variable. The shader doesn’t generally know how to handle that, since it’s typically supposed to be compiled into a one-and-done sort of process.

Let’s use a simple (numerically) example, 640x480 vs. 64x48 resolution. If, at 640x480, you sample 10 pixels in a row on each side of the current pixel (21 total), you’re grabbing 3.3% of the total width and 4.3% of the total height of the screen. If you grab 21 consecutive pixels from 64x48 resolution, that’s 33%/43% screen width/height sampled for the blur effect!

Okay, so going on a per-pixel basis is no good with that resolution difference. How about percentage-of-screen instead? Well, you run into the opposite problem instead: If your samples taken cover, say, 2% of the width/height of the screen, then a majority (all) of the pixels sampled at 64x48 resolution will sample THE SAME PIXEL, resulting in no blur at all. Likewise, the pixels sampled at higher resolutions will no longer be adjacent to each other, making the effect more visually confusing.

Because of the way Shaders are compiled, there’s not really room for extreme versatility here. The ideal would probably be to have a small collection of blur-effect Shaders, where each type can be used for different resolution ranges.

Either way, adding in this sort of versatility would mean re-implementing Depth of Field for yourself to take advantage of a variety of Blur Shaders to use in the process.