What have I been up too lately?

Hello (potentially two people that might read this blog),

What have I been up too since I graduated from SAE Institute?

Well firstly, I was bestowed the honorary title of “Unemployed” and now have to worry about many adult things like, finding some sort of income among other things.

But what about projects (I hear no one ask), well I have been working a few things in my lots of spare time. The first thing I did was actually go back to another project I started a long time ago and try to continue it. I was a portal/transition system I was working on that was inspired by Anti-camber however it didn’t get very far and ultimately I stop as I couldn’t progress on it.

Now however, I have a piece of paper saying im smart and can actually do things, and do things I did making some improvements over the system and allowing an actual transition between two planes. (I will now go over my system and explain how it works and how I am going to improve it in the future).

Here is the current effect:

StencilandRendering

So the system has two parts to it, Stencil Shaders and Render Textures. The Render Texture is what causes the actual transition between two planes and the stencil shader is used to mask the transition and make it look like your actually moving between areas.

How they work?

Lets go over the transition first, You will need two cameras for this, One camera will render PlaneA and the other will render PlaneB.

Snap1.PNG

Next we need a render texture, I made a short script that will get both camera on the player, Create a render texture and place it on the second camera and when a function was called would move that render texture to the first camera and swap the camera references around.

Snap2.PNG

This will move the render texture between the two cameras on function call and you won’t need to keep updating the reference of the cameras themselves. (Just make a quick function to call the swap).

Should work like this:

Portals2

Transitioning through a door way is quite easy, I just use a quad. Quads are like one way walls that you use, I place on in the centre of the door and make it a trigger. I then made a quick OnTriggerEnter() function to call the camera swap when the player enters the quad.

Result:

Portals3.gif

Yeah, a transition is happening now 🙂 Next we need to mask it. Here is where the stencil shader comes in. So what is a stencil shader? a stencil shader works very similarly to a regular shader that any texture rendering material would use. The only difference is that each pixel is will be encoded with a reference value which can be used to determine what pixels will be rendered and which aren’t.

First we need two regular image effect shaders, one for the placing on object that we want to hide and only render when needed and the other will be used to revel those hidden objects.

Hide Objects:

Snip4

Revel Objects:

Snip5.PNG

What does this mean? well the stencil part is where the magic happens,

Ref – is the reference number you place into each pixel

Comp – Comparing the reference value

Pass – What happens if the Comparison passes?

we want the comparison to equal so that both object have the same reference value before anything happens. If it passes, I want to replace my current pixels with that of the other object.

adding these to materials and placing them on your planes and quad (and setting the reference value to something other then 0) will cause an effect similar to this:

Portals5.gif

(Keep in mind a few things might be wrong with yours) Issues I had were that the stencil shader would cause the camera not to render the plane you are currently on. How I solved this was to duplicate both planes and and how no stencil or layer attached to then so they just loaded normally. I know it poor in many ways but there many things I’m trying to fix and this is one of them.

After that you need to transition back. I used a similar script as the camera swap but just swapped which quad in the door was active so I didn’t have multiple colliders going off at once.

And that is my current system. Many things to keep working on and thanks for reading 🙂