DOF for Weapon

Hi,

We found that in the latest version of UE5, a brand-new first person rendering system has been implemented.

So I’d like to know, under this new first person rendering, is there a good way to implement DOF blur for weapons?

For example, in aiming mode, only the weapon is blurred while the rest of the scene remains unaffected by DOF.

[Image Removed]

Including the arms, which should also remain unaffected by DOF, with only the weapon being affected.

If the new system cannot achieve this, then are there any other good ways to implement this effect?

We tried using PP DOF to blur the weapon, and then a PP material to blur the distant scene, but the result wasn’t very good. It was difficult to accurately control the DOF, and the character’s arms also got blurred. So we’d like to see if there are any official recommendations or demo examples we can reference.

[Image Removed]

Hi!

There is currently no special logic for this, but we might add some FP specific controls to DOF in the future. However, at this time there hasn’t been a proper investigation into what exactly is needed or desired here, so you bringing this up is very much of interest to us! If you’re using deferred shading and disable “Allow Static Lighting” in the project settings, (opaque) first person primitives will be marked in the GBuffer with a bit, so if you’re not already doing this, you could read that IsFirstPerson bit in a PP material to do FP specific logic there. However, this will simply tag all first person primitives, not just the weapon, but arms as well. Assuming your goal is to make arms more in focus, you could maybe just use the SceneDepth value (divide it by the FirstPersonScale factor which you can query with the ViewPropertyNode to get the non-scaled world space distance/depth) and then drive the DOF COC (circle of confusion) based on that?

Also it’s a bit hard to tell, but your first screenshot looks like it has roughly the same DOF strength on both arms and gun, but some additional motion blur on the gun?

Let me know if this helps you or if you have any concrete features you’re missing which we could possibly integrate into a future version of UE!

Cheers,

Tim

Hi,

Thank you for sharing this. I’ll try out the solution you suggested. Our ultimate goal is to achieve an effect similar to the first screenshot, where DOF can be applied to the arms, but the blur effect on the weapon is stronger.

As for the first screenshot, it’s from the game Battlefield. In that shot, both the arms and the weapon have DOF applied, but the weapon also seems to have an additional layer of motion blur. I’m not sure how that was achieved. Does UE have a similar way to apply an extra blur effect specifically to the weapon?

Hi,

I am not aware of a mechanism for adding extra blur to specifically just the weapon, but maybe you can use the method I suggested earlier + a custom blur in a post process material? That way it’s only applied to objects you care about and you can control the strength on scene depth or whatever other parameter is most suitable for you. I suspect that in your first screenshot the additional blur on the weapon could be a combination of DOF and motion blur.

Hi,

Thank you very much for your suggestion!

My understanding of your proposed solution is: in a post-process material, we can use IsFirstPerson to achieve first-person-specific blur, and then use SceneDepth and FirstPersonScale to exclude blur effects on the arms. Finally, we apply this material to the PP and adjust the DOF COC. If we want the weapon to have an additional layer of blur, we can implement a custom blur in the PP material and, through something like SceneDepth, make it affect only the weapon.

Could you confirm if my understanding is correct?

Also, regarding the first screenshot, it does seem to be as you described, but it looks like UE doesn’t provide a way to apply motion blur only to first person rendering?

It seems the only option is to implement a separate blur effect in the PP material. We have tried some custom blur implementations, but the results were not very good. Do you have any recommended approaches for custom blur solutions?

Hi,

Almost; my suggested solution is this pseudo code which you’d implement in a PP material node graph:

First, you want some logic to calculate how much a certain pixel should blur over other pixels:

float GetCircleOfConfusionForPixel(float UV)
{
    float CircleOfConfusion = 0.0f
    if (IsFirstPerson(UV))
    {
         float SceneDepth = GetSceneDepth(UV) / ViewProperties.FirstPersonScale;
         CircleOfConfusion = CalculateCOC(SceneDepth);
    }
    return CircleOfConfusion;
}

CalculateCOC() is some custom logic you’ll have to write to determine how blurry a certain pixel is, depending on distance from the camera and some uniform camera parameters (e.g. focus distance). If you want to set things up such that the arms are sharp-ish and the weapon is blurry, you’d set the focus distance very close so the arms are in focus and the weapon is out of focus. You could do something physically based here or something completely artistic.

And then you can use that function in your blur. You can do a very simple blur and just use the result of that GetCircleOfConfusionForPixel() function to determine blur strength (radius of the blur). That’ll work for the most part but you’ll get a hard outline around your first person geometry where the weapon doesn’t blur over the scene geometry and only blurs “within itself”. You can fix that by doing a more complex blur, where you do a blur at maximum radius but reject all samples where the COC of that sample does not overlap the current pixel (so you pass the UV of sample N to GetCircleOfConfusionForPixel and then only accept it of SampleCOC >= distance(CurrentPixel, SamplePixel)).

In essence what I’m describing here with broad strokes is how to implement a custom DOF that only applies to FP pixels. Unfortunately UE doesn’t seem to directly expose the COC used for DOF, so if you have the engineering capacity, I’d suggest looking into modifying UE’s native DOF implementation to apply that custom COC logic to where it calculate the circle of confusion. That should be a fairly minimal change because you only need to inject some custom logic in that one stage and don’t need to reimplement DOF. If that’s not possible, then I’m afraid you’ll have to implement a custom DOF effect in a PP material which will be a bit trickier but won’t require changes to engine source code.

I hope this info is helpful!

Cheers,

Tim

Hi,

Thank you for your suggestion. We will try modifying the engine to implement a first person based dof effect.

Glad I could help!

[Image Removed]I just discovered that in Call of Duty, there’s a separate option to enable motion blur specifically for weapons. I’d like to know if Unreal Engine 5 might include a similar solution in the future. It seems like a very practical feature for first-person games.

I previously considered implementing first-person motion blur myself, but I wasn’t able to make it work.

Hi!

There are currently no plans to add something like this for the future, but it shouldn’t be too hard to disable motion blur on FP pixels by simply checking the FP bit in the gbuffer when calculating motion blur. We’ll keep this feedback in mind, so there’s a chance we might end up adding this in the future!

Cheers,

Tim

Got it, thank you for your reply. I hope this feature can be implemented in the engine soon, as it’s a fairly common feature for FPS games.