How to make foreground blury but not the skybox?

I got a terrain, and i wan’t to make it blurry in foreground. But when i do it with DOF my skybox become blurry too. Is it possible to prevent my skybox from blur?

Thx

This is fairly easy to accomplish. You’ll need to find the part of the shader where it samples the DepthBuffer, and change it such that if it gets back the maximum depth, it uses the focal depth instead.

For example, I am using component “Depth of Field (Lens Blur, Scatter, DX11…)” and with my current settings this is implemented using DepthOfFieldScatter.shader. In that file, making the following change to function fragCaptureCoc will keep the skybox from getting blurred:

float d = SAMPLE_DEPTH_TEXTURE(_GBuffer, i.uv1.xy);
d = Linear01Depth (d);
+float isSkybox = floor(d);
+d = lerp(d, _CurveParams.w, isSkybox);

(add the lines marked with a +, without the + itself)

As @robertbu stated, you could do this with different cameras. If you had one rendering your scene (with clear flags set to depth only), and had another camera (with a lower depth) render the skybox only (LayerMask set to none, clear flags set to skybox), then you could render the skybox and then paint the scene over it with the second camera. BTW: both cameras would be in the same position and orientation in the scene (technically position isn’t important, just orientation, but it’s easiest to make one be the child of the other).

If you have any questions about using multiple cameras, and what layermasks and clear flags are, check the camera documentation and check around here and the forums - there are a number of posts on doing so.