Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Using Cameras and Culling Masks to selectively display items

Discussion in 'General Graphics' started by ewajs, Nov 30, 2021.

  1. ewajs

    ewajs

    Joined:
    Dec 12, 2019
    Posts:
    5
    Hello everyone,
    I'm trying to achieve something that seems simple (at least to state) but due to my lack of experience with the 3D world and its various concepts has proven to be tougher than I assumed, so I'm reaching out for help.

    Basically the problem statement is as follows: I'm building a configurator in which users can load artworks into a gallery building. Prior to them doing so, there are placeholders that display a number for that artwork position in the gallery. Users can move artworks around the plane they sit in so it is possible that a given user might overlap two artworks or put an artwork on top of another placeholder. If this happens, I want the placeholder to still show through the artwork so the user has feedback that there's a hidden slot there.

    To achieve this I did some research and it looked like the solution was to have a Secondary Camera with higher depth than the Primary Camera, have both of these cameras have the same position and move in unison, have this Secondary Camera Clear Flags set to Depth Only, create a dedicated layer for the placeholders, have this as the only layer in the Secondary Camera's Culling Mask, have the Secondary Camera have a greater Depth than the primary and, lastly, exclude the mentioned layer from the Primary Camera's Culling Mask.

    This sorta achieves what I was looking for, here's a screenshot of the results:
    Screen Shot 2021-11-30 at 5.19.37 PM.png

    This is almost perfect, the placeholder number is showing although the artwork frame and canvas are over them, however the problem is that we see numbers for placeholders that are far off in the distance, behind walls. I completely understand why, as the walls are not in the Secondary Camera's Culling Mask so why would they be omitted?

    My assumption was then "Just also add the walls to the Secondary Camera's Culling Mask and you'll be good to go". But I was sadly wrong and can't seem to understand why or how to overcome this. If I do that, for some reason the Canvas and Frames disappear, here's what happens:
    Screen Shot 2021-11-30 at 5.28.42 PM.png

    Now the walls properly occlude placeholders that should not be shown, however the frames and canvas have completely disappeared although they are there (I can bump into them with the player). Moreover, what's difficult to understand for me is that these are on an altogether different layer and for some reason the rendered scene hides all of the artwork although most of it does not overlap at all with the placeholder (for example, the frames do not touch nor are in front of it whatsoever, why are they being hidden?).

    I'm guessing this might be related to my game object structure and nesting, the artwork as a whole is a prefab with this structure and layers (in RED layers on the Primary Camera's Culling Mask and in BLUE the Secondary):
    - Artwork (Empty GO @ Default Layer)
    --- Frame Components (Empty GO @ Artworks Layer)
    ------ Mat (Quad@ Artworks Layer)
    ------ FrameBars (Empty GO@ Artworks Layer)
    --------- FrameBarLeft (Cube @ Artworks Layer)
    --------- FrameBarRight (Cube @ Artworks Layer)
    --------- FrameBaTop (Cube @ Artworks Layer)
    --------- FrameBarBottom (Cube @ Artworks Layer)
    --- Canvas (Cube @ Artworks Layer)

    --- PositionText (TextMesh @ ArtworkPlaceholders Layer)


    Hope this is a good problem statement/description and thanks in advance for the time and help.