I noticed that the Depth Of Field effect gets less blurry the smaller I shrink my screen. Is there a setting for this to make it not do that?

Check out this discussion: https://github.com/Unity-Technologies/PostProcessing/issues/29

At the end there is a solution for an adapting Blur Kernel

Thanks, Iāll give it a try.

Itās still an issue and that solution only works for some.

If you only need distance blur, another workaround is to fake it by creating a plane (no collider and layer to ignore raycast) with a gaussian blur shader/material applied to the plane. Since itās a gameobject, itās not impacted by screen resolution changes. If your character moves/rotates, you can just rotate the object and/or move the object to keep the same distance from the player/camera without any hit to fps. You can get fancy and create multiple āpanelsā to stack the effect with different levels of blurs or colors for special effects. This wont work for tilt shift or other lens-type simulation effects.

ty clover, Iām going to just try this with a sphere around the active camera

@cloverme Now if only I knew how to actually make a shader that I could stick on a sphere that works as a blurry lensā¦ : (

EDIT: Alright hereās a shader that may or may not work for you, create a sphere that stays around the camera and basically grow or shrink it for distance in a custom cs script:

Save this first as Blur.cginc:

```
// https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson5
float4 gaussianBlur(float2 dir, float4 grabPos, float res, sampler2D tex, float radius)
{
//this will be our RGBA sum
float4 sum = float4(0, 0, 0, 0);
//the amount to blur, i.e. how far off center to sample from
//1.0 -> blur by one pixel
//2.0 -> blur by two pixels, etc.
float blur = radius / res;
//the direction of our blur
//(1.0, 0.0) -> x-axis blur
//(0.0, 1.0) -> y-axis blur
float hstep = dir.x;
float vstep = dir.y;
//apply blurring, using a 9-tap filter with predefined gaussian weights
sum += tex2Dproj(tex, float4(grabPos.x - 4*blur*hstep, grabPos.y - 4.0*blur*vstep, grabPos.zw)) * 0.0162162162;
sum += tex2Dproj(tex, float4(grabPos.x - 3.0*blur*hstep, grabPos.y - 3.0*blur*vstep, grabPos.zw)) * 0.0540540541;
sum += tex2Dproj(tex, float4(grabPos.x - 2.0*blur*hstep, grabPos.y - 2.0*blur*vstep, grabPos.zw)) * 0.1216216216;
sum += tex2Dproj(tex, float4(grabPos.x - 1.0*blur*hstep, grabPos.y - 1.0*blur*vstep, grabPos.zw)) * 0.1945945946;
sum += tex2Dproj(tex, float4(grabPos.x, grabPos.y, grabPos.zw)) * 0.2270270270;
sum += tex2Dproj(tex, float4(grabPos.x + 1.0*blur*hstep, grabPos.y + 1.0*blur*vstep, grabPos.zw)) * 0.1945945946;
sum += tex2Dproj(tex, float4(grabPos.x + 2.0*blur*hstep, grabPos.y + 2.0*blur*vstep, grabPos.zw)) * 0.1216216216;
sum += tex2Dproj(tex, float4(grabPos.x + 3.0*blur*hstep, grabPos.y + 3.0*blur*vstep, grabPos.zw)) * 0.0540540541;
sum += tex2Dproj(tex, float4(grabPos.x + 4.0*blur*hstep, grabPos.y + 4.0*blur*vstep, grabPos.zw)) * 0.0162162162;
return float4(sum.rgb, 1.0);
}
```

Save this as Blur.shader:

```
Shader "Custom/Blur"
{
Properties
{
_ClearColor ("Clear Color", Color) = (1,1,1,1)
_FogColor ("Fog Color", Color) = (1,1,1,1)
_BlurRadius ("Blur Radius", float) = 3
_MaxAge("Max Age", float) = 3
}
SubShader
{
Tags
{
"Queue" = "Transparent"
}
Cull Front
// Grab the screen behind the object into _BGTex
GrabPass
{
"_BGTex"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Blur.cginc"
/**/
// Properties
// set in material
uniform float4 _ClearColor;
uniform float4 _FogColor;
uniform float _BlurRadius;
uniform float _MaxAge;
// grab pass
uniform sampler2D _BGTex;
uniform float4 _BGTex_TexelSize;
// set by script
uniform sampler2D _MouseMap;
uniform float _MaxSeconds;
struct vertexInput
{
float4 vertex : POSITION;
float3 texCoord : TEXCOORD0;
};
struct vertexOutput
{
float4 pos : SV_POSITION;
float3 texCoord : TEXCOORD0;
float4 grabPos : TEXCOORD1;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = UnityObjectToClipPos(input.vertex);
output.grabPos = ComputeGrabScreenPos(output.pos);
output.texCoord = input.texCoord;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
float4 bg = tex2Dproj(_BGTex, input.grabPos);
// younger = redder
float timeDrawn = tex2D(_MouseMap, input.texCoord.xy).r;
float age = clamp(_Time.y - timeDrawn, 0.0001, _Time.y);
float percentMaxAge = saturate(age / _MaxAge);
//return float4(percentMaxAge, 0, 0, 1);
// older = higher percentMaxAge = more blur
float blurRadius = _BlurRadius * percentMaxAge;
float4 color = (1-percentMaxAge)*_ClearColor + percentMaxAge*_FogColor;
float4 blurX = gaussianBlur(float2(1,0), input.grabPos, _BGTex_TexelSize.z, _BGTex, blurRadius);
float4 blurY = gaussianBlur(float2(0,1), input.grabPos, _BGTex_TexelSize.w, _BGTex, blurRadius);
return (blurX + blurY) * color;
// TEST
//float blurRadius = floor(_BlurRadius * mouseSample.r);
//return mouseSample; // test mouse map
//float noSmudge = mouseSample.r != 0; // test erasing blur
}
ENDCG
}
}
}
```

I added in the āCull Frontā part of this shader so that your sphere shades the inside.

Create a material and set fog color to RGBA 0.5, 0.5, 0.5 and alpha can be anything. It should create a blur.

To anyone that ends up here looking for solution and gets frustrated over GitHub link not working, like me:

Weāve ended up compensating for this issue by scaling the offset of texture sampling in the Bokeh pass by the ratio of current to the reference resolution.

So `float2 duv = float2(disp.x * _RcpAspect, disp.y);`

became ```

float2 duv = float2(disp.x * _RcpAspect, disp.y) * _ResolutionCompensation;

```
This isn't perfect. You might get slight artefacts noticeable in higher resolutions, but for us, it did the job of making DoF look close enough in 4K, 1080p and 720p.
```

Thank you @lczyzycki7lvls for posting a simple solution that works.

Hi, how did you calculated the resolution compensation?

Itās the height value in the current rendering resolution divided by the height of the resolution for which the effect was initially set and tweaked. For us it was 1920x1080, so y / 1080. You can set it where all the other DoF parameters are set, in Render function in DepthOfField.cs:

`sheet.properties.SetFloat("_ResolutionCompensation", context.height / 1080f);`

The algorithm change, so you can handle it in BokehDepthOfField.shader

change line from

```
half4 samp = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_LinearClamp, uv + disp.wy);
```

to

```
half4 samp = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_LinearClamp, uv + disp.wy * _ResolutionCompensation);
```

This can also be compute in PrepareBokehKernel function of DepthOfFieldPass.cs