- Home /
Rendering Depth Correctly With Multiple Cameras
I'm attempting to create a camera effect whereby the player the player can see normally hidden objects in high contrast. For example's sake, a set of footprints will glow red while the rest of the world has no color.
I initially attempted to achieve that with the use of two cameras. The first in the depth buffer (-1) is the main camera with clear flags set to skybox, and a desaturating post-processing layer was applied. Its layer mask contained everything except the footprints. Then the second camera is enabled, its layer mask containing nothing except the footprints, and arranged after the first camera in the depth buffer (0). This camera's clear flags are set to Depth Only. The footprint object glows red. The result is visually almost perfect; a greyscale environment, red footprints... but the footprints aren't obscured by objects rendered by the first camera, and it doesn't seem like there's a way to change that. It seems like at one point in unity there was, as this page alludes (and shows) exactly the effect I'm going for: https://blog.theknightsofunity.com/using-multiple-unity-cameras-why-this-may-be-important/ , but it seems that that's no longer supported.
For a stopgap solution, I've created a script for the footprints that simple runs a raycast from the footprint to the player during OnWillRenderObject() to detect any obstacles between the two, but for a variety of reasons this isn't a solid long-term solution. Too many footprints, and potentially more than one player.
I've looked into shaders and specifically stencil buffers to accomplish this, but my initial attempt at them didn't work, and I'm not very familiar with shader language to know what I might be doing wrong.
If anyone has any ideas for other ways to tackle this problem I might not be thinking of OR fixes about something I'm approaching wrong with the double cameras, let me know.
Your answer
Follow this Question
Related Questions
UI masking in a jet fighter HUD 0 Answers
Cutting a hole in the camera 0 Answers
screen flipped upside down [image effect] 0 Answers
EdgeDetectEffectNormals flips camera 0 Answers
Create a hole in a mesh using a shader 0 Answers