Search Unity

Rendering pixels only visible to a secondary camera/object

Discussion in 'Shaders' started by carlosbeneto, Aug 19, 2020.

  1. carlosbeneto

    carlosbeneto

    Joined:
    Apr 6, 2014
    Posts:
    1
    Hello!

    I've been dabbling in Unity for a while but never really had a need to dive into shaders. However, I'm now toying with a concept that most definitely needs shader magic but I'm quite lost with the terminology.

    Essentially I want to place a camera on a scene and then discard all pixels that are not visible by said camera. I believe playing with Z-buffers or stencils may be the way to go here but I may be way off track. The curveball here is that I'd be looking from a different, top-down camera as per the image below (quick illustration of what I'm after).

    [/IMG]

    I'm not looking for a ready-made solution but any pointers as to what to look at would be greatly appreciated! Thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Look up fog of war or shadow maps.

    The short version is you'll need to render out a depth texture from the point of view of the character, and sample that depth texture in all of your shaders to see if it's visible or occluded, and clip the pixels accordingly.