I’m wondering if it is possible to construct a plane that fills the camera’s fov at an arbitrary distance from the camera?
For instance, I have a plane with a texture on it that I want to fill the screen, but the camera must be in perspective mode (for other reasons that I won’t go into). And yes, it must be on a plane. I can’t use a GUITexture because it is drawn last.
The correct way to do this is to use GUITextures. Nevermind that it’s drawn last. I’ll get to this in a bit:
First, make a GUITexture, and set the Texture to whatever you want to cover the whole screen. Now, set all Pixel Inset values to 0, as well as all borders. Now set scale to (1,1,0) and position to (0.5,0.5,0). This causes the texture to take up the entire screen.
As for the drawing last thing:
Define a new layer called “BGLayer” or whatever, and set the GUITexture to belong to this layer. Now, create a new camera, and set its culling mask to draw nothing BUT the layer that contains the background. Set this camera’s depth property to a value which is less than all other cameras in your scene. -1, for example, and then all other cameras to 0 or above. All other cameras must have their Clear Flags set to Depth Only.
This causes the background to always get drawn first, because it’s rendered by a camera that always renders first. All other cameras then only clear the depth buffer, then renders their content right on top of your background, as you wanted.
I realise this topic is old as the hills, but you don’t need to rotate the plane in Update, just do it once in Start.
To make it always face the camera just parent it to the camera.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlaneScale1 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
float distance = Vector3.Distance(Camera.main.transform.position, gameObject.transform.position);
float height = 2.0f * Mathf.Tan(0.5f * Camera.main.fieldOfView * Mathf.Deg2Rad) * distance;
float width = height * Screen.width / Screen.height;
gameObject.transform.localScale = new Vector3(width / 10f, 1.0f, height / 10f);
}
// Update is called once per frame
void Update()
{
}
}
what is this plane for?
You could draw a plane with a couple triangles in clipping space and a specific shader that forwards the vertex original values to the pixel shader.
Elegant solution but depends on the purpose of the plane.