Having a plane fit the size of the screen relative to the camera

Hi, I’m currently trying to create a battle transition like in most turn based rpgs when your on the field and then a random encounter starts. I’m approaching this by taking a screenshot of the screen, have it display on a cracked plane which has an animation that has it break away.

My question is, how do i have the plane stretched to the size of the screen relative to the camera/screen size?

And i guess have an additional question which is, could this be done via GUI on unity?

What I’m trying to do is very similar to this - (6 seconds into the video) FINAL FANTASY X|X-2 HD Remaster - Original vs. Arranged Music Battle - YouTube

2 Answers

2

Well, the easiest way is to use a second orthographic camera which only renders your plane mesh. An orthographic camera is way simpler since it has a given height in pixels. The camera’s size is the half height of the visible area in world units. The width of the camera depends on your aspect ratio of your screen. So for example if you set a camera size of 0.5f the camera will be able to view one world unit from top to bottom. If you’re playing with a 1024x768 resolution your aspect ratio is 1024 / 768 == 1.333333

If you multiply your height by the aspect ratio you get the width of the viewable area. In our case it would be 1.333333 world units since the height is 1

You can simply get the aspect ratio from the camera

Since the aspect ratio might vary it’s best to simply resize your plane according to your aspect ratio.

So just

  • scale your plane to be square for example 10x10 world units
  • place the plane infront of your camera and center it.
  • make sure you placed the plane on an unused layer and set the camera to only draw that layer
  • make sure your main camera doesn’t renders this layer.
  • since our plane is 10x10 we need to set the camera’s size to 5
  • In a script you would now scale the plane in the x-axis according to the aspect ratio

Something like this:

//C#
public Transform planeObject;
public Camera planeCam;
void Update()
{
    var scale = planeObject.localScale;
    scale.x = scale.y * planeCam.aspect;
    planeObject.localScale = scale;
}

Now your plane should be viewed 100%. Keep in mind to check the depth value of your cameras so your plane camera is rendered on top of your main camera (this should be the default). Also you just need to diable the camera to hide the plane.

Hey there,

Here is the way to use a Quad that you created off-hand.
You would need to create a MonoBehaviour script that will be attached to the quad and have a post render with orthographic camera for rendering in screen space.
You shader (or any regular material) should simply render the texture / movie you assigned to it.
Here is an example how to do the Quad screen space render.

void OnPostRender() 
{
	if (BackgroundExists)
	{	// Perform the full screen render only if a background exists

		if (!QuadMaterial)
		{
			Debug.LogError("ScreenSpaceQuad::OnPostRender - Error: no  Material Assigned");
			return;
		}

		if (QuadMaterial.GetTexture( "_FrontTexure" ) == null)
		{
			Debug.LogError( "ScreenSpaceQuad::OnPostRender - no texture");
			return;
		}

		GL.PushMatrix();
		QuadMaterial.SetPass(0);

		GL.LoadOrtho();
		GL.Begin(GL.QUADS);
		GL.Color(Color.white);

		GL.TexCoord2(0, 1);
		GL.Vertex3(0, 1, 0);

		GL.TexCoord2(1, 1);
		GL.Vertex3(1, 1, 0);	

		GL.TexCoord2(1, 0);
		GL.Vertex3(1, 0, 0);	

		GL.TexCoord2(0, 0);
		GL.Vertex3(0, 0, 0);

		GL.End();
		GL.PopMatrix();

		Debug.LogError("ScreenSpaceQuad::OnPostRender: done" );

	}
}

The screen space material is something you need to define by creating your own shader or use a regular existing one.
The adjusted quad will render to screen and it will be done after scene rendering was done so it’s a good trick to override the render.

There is another way to go by using Render to texture and then OnPostRender but it seems to be bit out of this scope and requires some tricks or usage of Unity Pro.

Hope that helps,