- Home /
Resizable Virtual Screen in Unity
All the virtual screen technologies I've seen in Unity so far have limited the screen to the size and resolution of the desktop that the remote computer is duplicating. I am looking to create a resizable virtual screen that convinces the remote operating system that it is publishing to a desktop of that size. Note that I am referring to resizing vertically and horizontally, not just proportionally. For example, emulating a physical desktop screen that is 12" tall and 100" wide.
Have any such Unity technologies been developed? If not, are there any technology recommendations on which I can make this capability for the community?
Answer by BladeSides · Jun 16, 2020 at 01:58 PM
I believe you are referring to supersampling, which means to render something at a higher resolution and then scaling it down. It can be achieved by using a RenderTexture and multiplying the Screen Width and Height by the factor you want to increase it by. For example, if you want to render 2880*1620 on a 1920*1080 screen, the factor would be 1.5.
An example script would be:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.ImageEffects;
public class supersampling : MonoBehaviour {
[ExecuteInEditMode]
RenderTexture RT;
public Camera cam;
const int factor = 2;
void Start () {
RT = new RenderTexture (Screen.width*factor,Screen.height*factor,24, RenderTextureFormat.ARGB32);
}
void OnRenderImage (RenderTexture source, RenderTexture destination) {
cam.targetTexture = RT;
cam.Render();
cam.targetTexture = null;
Graphics.Blit (RT, destination);
}
}
You may modify it further by adding custom factors for X and Y coordinates. This should be enough to get you going.
Thanks mate. I'm not just talking about proportional sizing-- that could definitely be achieved with scaling as you mentioned. I'm talking about having an odd screen size-- say 12" tall and 100" wide-- and the OS will be able to drag windows across the entire screen (not just stretch the existing display horizontally)
You have the ratio of virtual screen and the ratio of display. I used to solve it by math.
your question is a bit confusing, as it can be sth like full screen(cropped), or fit screen in correct ratio(with dark/empty area). Thus, you should better provide some reference in picture or drawing. It may help other to understand your need easily.
I'm saying I want the ratio of the virtual screen from its host computer to adapt to the ratio of the Unity object that displays the screen contents. I'm not looking to stretch the inco$$anonymous$$g video stream, but to actually emulate an elongated physical screen, even if it isn't the same screen ratio as the host computer's screen.
I want to actually "convince" the host computer that it is publishing to an extra-wide physical screen, let's say.