Okay, so for a project I’m working on I wanted to have one room that looks like it’s in space, where if the player looks around all they see (aside from objects inside the room) is the starry sky—except through the passages to another room. To accomplish this, I thought maybe I could use two cameras, the back camera in an enclosure with just the starry background, and the front, main camera showing the player’s surroundings, and then I’d give the exterior walls of the room a depth mask shader.
Basically, like this: note that the skybox is visible through the circular opening in the wall, which is exactly what I want. (Eventually there’s going to be a connection to another room or corridor there, so it won’t just be open to the skybox, but that’s beside the point for now. The blue circle is intentional; that’s there to indicate to the player the boundaries of where they can walk.)
I’m having trouble getting this to work as intended, though. The instructions on this page do seem to work:
http://wiki.unity3d.com/index.php/DepthMask
…as long as I put that “SetRenderQueue” script on every object outside the astronomy room. The problem is, well, that’s a lot of objects, and it seems like a less-than-ideal solution to have to put a script on every single object in the entire scene except the handful of objects in this one room.
That same page does have a suggestion about what to do if you want to mask a lot of objects:
“In most common scenarios, you will only need a few objects to be masked. If, however, you find that you have more objects that need to be masked than objects that do not, you might find it useful to attach the SetRenderQueue script to the masks themselves, and set their queues to 2090 (just before regular geometry). Objects that you don’t want masked should have their queues set to 2080 (just before the mask shader).”
So I tried that, and I got… well, I got what’s shown in the above image. Looks great… until I turn around. And then I see this:
All that geometry there, that tall rectangular column and the smaller corridor, is outside the room with the Depth Mask shader on its walls, and therefore it should be masked out… or so I thought. But it’s not. I don’t want all that stuff to be visible from inside the room; I just want the starry sky to show there.
I did a lot of web searching to see if I could find a solution to this, and I found a number of other depth mask shaders online… but they all had the same issue; they didn’t mask out the objects outside the room. Here are some of the other sites I found with shaders that I tried, with similar results:
https://github.com/doomlaser/DepthMask-Unity-Shader
http://www.pixelplacement.com/2011/02/15/masking-in-unity/
I admit I don’t know much about shaders in Unity yet; I’m trying to learn, but it seems like there’s a lot to absorb there. But if anyone could point me in the right direction and let me know how I could create a depth mask that masks out the objects outside this room, I’d really appreciate it. (Or am I taking the wrong approach entirely, and is there a better way to do this that doesn’t involve depth masks at all?)
Thanks.