- Home /
In-world "screen" from camera?
Background
I've made a prototype of a space simulator, It's based loosely on the idea of a "space shuttle simulator". I'm going for the realistic approach, which means that I'm trying to shun exterior views.
The problem
I want to have screens in my cockpit, so the player can swivel their head and look at a virtual screen. I've been using "Normalized Viewport Rectangles" in my prototyping process; but that's not a permanent solution. I am unsure if this is possible, and even more unsure of where to begin my research.
Any pointers in the right direction would be appreciated!
-Frank
Answer by Bunny83 · Jun 22, 2014 at 09:17 AM
For this you need Unity pro since you need RenderTextures
It's possible to workaround that limitation in the Free version, but it has horrible performance as you would use Texture2D.ReadPixels.
edit
Well, you can get the effect of a RenderTexture with a script like this:
// C#
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Camera))]
public class CustomRT : MonoBehaviour
{
public Rect rect;
public Material mat;
Texture2D texture;
void Start()
{
camera.pixelRect = rect;
texture = new Texture2D((int)rect.width,(int)rect.height,TextureFormat.ARGB32,false);
mat.mainTexture = texture;
}
void OnPostRender()
{
texture.ReadPixels(rect,0,0);
texture.Apply();
}
}
Do the following steps:
Attach the script to a second camera.
Change the camera's depth to be rendered before your main camera
Create a material and assign it to the "mat" field
Choose a rect size for the RT. Note: You can't use a larger size than your screen has!
Use the material on whatever geometry you like
The result looks like this:
webplayerExample
ps: I've added a link at the bottom to a UnityPackage which contains the example scene.
Wouldn't this just "screenshot" from somewhere on the "main viewport"?
The CPU-issue on the free version, I can live with until I have a "marketable product", (I'll just have a VERY low frame-rate on the virtual displays)
Ah! YES!! this is awesome! (the documentation was a bit vague, but an example like this isn't)
Thanks!
Your answer
Follow this Question
Related Questions
why my unity games run on android devieces,the screen will be wrong. 0 Answers
how to have an object positioned relative to the screen(like a button) 1 Answer
UI render doesn't sync with Camera movement 2 Answers
Why doesn't my players camera work and why does it spaz out randomly 1 Answer
Keeping screen width and scaling screen height for different screen resolutions 2 Answers