Can I make objects invisible when entering a collider?

I want make the character get the sword through a portal, but without the sword show up in the sphere collider region (see the print below, i hope that you can understand)

I can think of two ways of doing this.

  1. Shader - discard all pixels behind the portal plane.
  2. During transparent pass render invisible object that will hide part of the sword behind portal (cylinder or something) but enable write to depth-buffer and than render sword also during transparent pass. Effectively this will not show sword in places where depth buffer is already written.

how exactly can i make the first option? I tried to do the second but I couldn’t understand xD

If you don’t understand second than you will not be able to do the first one anyway.
Please do some shader tutorials first.

Also, please note that this is the physics forum and your post is about rendering. There’s dedicated graphics forums here.