Realistic Depth of Field Module [Open Source]

Hello! I’ve recently created a module that allows for a “realistic” depth of field effect in games. It raycasts from the center of your screen to where you are looking, and sets a DepthOfFieldEffect’s FocusDistance to the magnitude between the two points.

This emulates how your eyes focus on things in real life, hence why I’ve called it Realistic Depth Of Field.

If you’re having trouble figuring out what I mean, here is an example video (note the setting “SmoothTransitions” is enabled in this video, which is by default disabled):

Example use:

-- in a local script!

local m = require(path.to.module)

local settings = m:GetDefaultSettings()

settings.SmoothTransitions = true
settings.InFocusRadius = 30

m:ApplySettings(settings)

m:Start()

Need documentation or information about the module’s settings? It can be found here:

No credit is necessary if you plan to use this module, but please reply with cool creations you’ve made!

Find it here:

69 Likes

Looking pretty nice :slight_smile:

Roblox all ready has depth of field

1 Like

It quite literally only takes reading the first 2 sentences of the post to understand the difference between Roblox’s DoF and Wizrred’s module…

30 Likes

This is awesome. I am currently working on a game that I hope can mimic the first-person experience of a real person.

1 Like

Looks great, but didn’t someone already post something like this on the devforums?

1 Like

Are you referring to this post? My module is definitely similar, but it has more customization features and doesn’t raycast from your mouse’s position.

You can think of my module as an alternative to that one!

Ah, thanks for clearing up the confusion.

1 Like

Yes, Roblox does, but this is a module that lets you control the depth of field with the camera.

Pretty cool! I will use this for my game. Although your video preview is either a really short gif, or corrupted. So I cannot see how is it looking like, on mobile.

3 Likes

Super sorry for my late reply. The video preview has been fixed. The file hosting service I used is a bit peculiar so I’m not sure how long it’ll be up for, but if it breaks again I’ll fix it.

Cool, so what am i suppose to put this script at in Roblox Studios?

Anywhere a local script can access, as it needs to be called from a local script. I would put it in ReplicatedStorage.

1 Like

Is there a way to exclude certain objects from the DepthOfField(e.g. the front sight of a gun is unblurred, while the back is)?

I’m so sorry for my late response! Haven’t been on Roblox much recently.
Yes, there should be a way to blacklist parts and models.

RealisticDOF:AddToRaycastFilter(part)

2 Likes

Does this still work? did I install it right?

image

Thanks for referencing my archaic post haha

Good work on this module looks great

i think the video is corrupted or is it only me?

It’s an interesting module, but I feel like it would need eye tracking (if that was possible on Roblox) for it to really feel nice. In third person, The raycast basically always hits your character so that is not ideal. In first person, it does behave ok. I changed it to raycast to where the mouse was and um, it was very distracting

Broken for me as well