Any good way how to set up a depth of field for the camera?

I’ve tried some filters with a depth of field and it keeps on blurring everything near the player.
For example, I’ve tried to use filters from this tutorial:

What I wanted to achieve is to make everything near the player sharp and just blur the far away area.
This filter seems to work with a first-person camera. But if I use a third-person camera, it blurs the player.
Any idea what to use to achieve this?
The Depth of field in the camera itself doesn’t seem to do anything.

hi! use filter DOF - distance of fog - this is filter you get from addon post processing for bge version 2.79 and this filter work for horizont line and not activate nearest objects

1 Like

Thank you, these filters are great.
But how do you set the DOF correctly? It still blurs anything near me.

Look for this in the code:

float znear = 0.10; //camera clipping start
float zfar = 230; //camera clipping end

The main camera should have the same values
camvalues

Yes, I have it set up correctly for the znear and zfar.
What kind of filter do you use?
When I use the DOF filter I get this:

It only shows sharp objects that are in the center of the camera.
Since the game, I’m working on has a third-person camera and not a first-person camera, the main character is always blurred.

such is the nature of DOF, basically, its working as it should. DOF is a cinematic effect to bring focus to a element in the scene. for games, however, its less than ideal since the whole scene is basically “of interest”.

ive always stood by DOF isnt for games. its just wrong and looks bad.

Well, the thing I wanted to achieve is to blur the background.
But I wasn’t able to achieve that with any filters.

if you right looking tutorial - Tatimster says that for DOF you need to set the distance because the standard distance by default is 0.500

That is,because the focus of the dof is at the cursor/center of the camera. Meaning where ever the camera is looking at, that will be crisp, everything else will be blurred out. as i look at your picture it does exactly that.

Here is an example of the filter i use, and to tell @Daedalus_MDW that the filter is perfect for games, depending on what game you are creating, for example in first person view it works perfectly fine, as you can see in an old video of mine.

Timestamp 1:

Timestamp 2

Is there a filter that will always blur something in the background, leave objects in front sharp and not adjust to what is in front of the camera?

First of all my filter/glsl knowledge is very limited.

But i don’t think that there is a filter for 3rd person, due to the fact the filter would need to calculate the distance for every object, every tic. This will make the filter so resource heavy that it isn’t doable. Also not sure if a filter can do those calculations.

For a 3rd person i would say:no luck, but if you make a side-scroller or first person view then you could play with the filter options to be able to give good results.

Maybe @sdfgeoff could explain it, he got a lot more understanding of glsl

You need to set manualdof to true and autofocus to false, then set the manual values to something like this:

float ndofstart = 0.0; //near dof falloff start
float ndofdist = 10.0; //near dof falloff distance
float fdofstart = 10.0; //far dof falloff start
float fdofdist = 20.0; //far dof falloff distance

fdofstart is the distance at which objects start to defocus, fdofdist is the distance at which everything will be blurred.

Example with those manual values:

Notice that the sphere in the back is in the center(ish), yet it is out of focus.

1 Like

Yes, this works exactly the way I wanted, thank you.
One thing though, I don’t know if you can get rid of it or not. This filter creates some sort of outline around objects.

If you look closely at this screenshot, you can see the outline around the top of the forklift.
Is there any way how to get rid of it, or there is no way?

You can set depthblur to false. It will get rid of that 1 pixel outline, but the blur around close objects against far objects will require some range check, at cost of performance.

1 Like

Thank you for the info, it works great.