Deph of field on portal shader

Is it possible to add a depth of field through the portal shader?

The Portal just moves the ray to another place, so any depth of field calculation will get a new depth…

The plane has a portal shader, with position set to 1 BU behind the plane (in the view direction)

1 Like

For example, i need to blur only the items inside the portal
image

some modification in the shader of the portal, maybe

There are plenty of ways to do something like that… They all have some minor differences, and you should know exactly what you’re aiming for.

If you use Depth of Field, you’ll get the focus/unfocus effect for the whole scene. All objects that are at the correct focal distance will be focused and the rest not (depending on your apperture settings)… The portal won’t change the focal distance, but by breaking the camera ray into a new ray and direction will produce a different distance to the objects. If at that new distance, the objects are out of focus, then you’ll get the blur… And the same happens in the other way, as my example shows (portal puts object at the focal distance by shortening the camera rays).

The portal node also allows you to create a ‘focus’ system, by controlling preciselly the position and directions of the outgoing rays, thought is a bit more heavier math for most users. But this would allow you to have Depth of field just in the through the portal (and disabling the DOF from the camera).

Other options, would be doing it with the compositor. The blur won’t be the same, but it will be faster to work with.

1 Like

It worked, it was only linked to the camera’s depth of field and it worked, I didn’t think that the blender would hit the camera’s distance to the objects inside the portal. Thanks for explanation!