Search Unity

Pass the camera through the stencil hole

Discussion in 'Shaders' started by hknylt, Jun 20, 2019.

  1. hknylt

    hknylt

    Joined:
    Sep 13, 2014
    Posts:
    16
    Hello to everyone,
    I want to make a hole in a wall using "Stencil" and pass through this hole with the camera. But when the camera gets close enough, I can see the wall in the hole as a line. I don't know much about Stencil. It sounds very complicated and I couldn't think of working logic. I searched the forums, but I didn't come across anything related to my camera problem. I can't figure out what the problem is. I hope you can help. Here is a picture of my problem and stencil values. Thanks.

    Untitled-1.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Presumably your hole is a quad or cube mesh, yes? If that mesh is slightly pulled away from the wall, then it'll clip against the camera's near frustum before the wall does. Where the "hole" clips it doesn't mark the stencil, thus doesn't hide the wall.

    You can try to put the "hole" perfectly on the same plane as the wall, or slightly inside.
     
  3. hknylt

    hknylt

    Joined:
    Sep 13, 2014
    Posts:
    16
    Wall is a cube mesh. Hole is quad mesh. The wall can also be a different and complex pattern. My goal is to cut a mesh (wall or a different model) and put a cube mesh (Flipped normals) behind it.

    The reason I do this is to create a portal effect by placing a cube behind the wall using a rendertexture as the texture. When I enter the portal at a rate of 50% and look at the wall at a 90-degree angle, I can see both worlds cut off from the center of the screen.

    Am I following a wrong strategy? All the mathematical operations I designed for the portal are correct (Camera calculations, projection matrix, etc.). But I don't have much idea how to put the portal renderer on a wall or a different model.

    exp.png

    I checked the hole location and put it exactly where it should be. But this time I encountered a problem like the following.

    p2.png

    As in the portal game, when I get close enough to the portal, the screen is split in the middle and appears in two worlds.

    portal2.png

    I've probably followed a wrong strategy. Anyone have any idea? Thanks for help.
     
  4. hknylt

    hknylt

    Joined:
    Sep 13, 2014
    Posts:
    16
    I still haven't solved the problem.