A magic window

Drums are an instrument, and about one-and-a-half weeks ago  I made a drum interaction to familiarize myself with making an an actual interaction. I had heard we wanted to do some sort of interaction where the player could play a drum. Fortunately, the framework created by Levi and Eric made it very simple to add new interactions.

drums2.gif

[later]

At one of the meetings we divvied up some of the necessary interactions that we knew were going to be in the game, while the design for the others could be fleshed out. I started working on the “Magic Window” interaction, an important part of the desert area. The initial idea was to have some objects that would be hidden when viewed in the open, but visible when viewed through a magic window.

After being given some advice from a fellow game programmer, I attempted to go the depth buffer route. Essentially you can enable cameras in Unity to pass along information to a shader that can be used to determine the depth of the objects that the camera is rendering, relative to the camera. So, going off of this, I had two cameras, one that only could see the magic window, and one that could only see the hidden objects. Then, I compared the objects’ depth to the window to see if they should be rendered. That produced this effect:

window3.gif

However, the problem with using the depth buffer is that several of our materials are either transparent, or not in the correct render queue to be rendered to the depth buffer. Supposedly, there’s a way to force such objects to render to the depth buffer, but I couldn’t figure it out. Plus, it got a bit messy since we’re using several cameras in the game.

It seemed like there should be an easy way to do this. After getting some advice to look for a more Portal-style approach, I did some research and found a free script/shader combo that was essentially what we were looking for. Basically, with this approach, we have a duplicate of the room containing the magic window. Then, there is a second camera that tracks the player camera and renders to a RenderTexture, which is applied to the magic window’s material. This method is built off of a reflection script/shader on the Unity community wiki.

After incorporating that into my testing scene for the Magic Window, it took some modification to get everything to work right. But, I ended up with this:

portal2.gif

The magic window idea was developed at further meetings. Primarily the magic window will be looking into the past (or some other realm on top of the current one). Additionally, the window will be able to rotate.

Implementing rotation took some more adjustments, but finally, it’s looking pretty good. The base is there, so now we can start building more complex interactions around it. Right now there’s just a very basic interaction where if you drag an object out from behind the window, it becomes visible.

rotate.gif

-wednesday-david

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s