- Home /
How to Render to Fullscreen Texture pixel perfect
Hi.
I want to render my whole scene to a texture which in turn gets put back in front of the camera so that it looks exactly like the scene but as a texture. The problem is that the way i do it currently the result is slightly off to the top right. So if i repeat this process several times objects appear to move (and get blurry).
Here is what I currently do.
     //Create a Texture object wich has the dimension of the //whole screen
     
 IEnumerator InitCombineTex()
     {
         yield return new WaitForEndOfFrame();
 
         Vector2 bottomLeft = UICamera.currentCamera.ViewportToWorldPoint(Vector3.zero);
         CombineTexture.transform.position = new Vector3(bottomLeft.x, bottomLeft.y, CombineTexture.transform.position.z);
 
         Vector2 topRight =  UICamera.currentCamera.ViewportToWorldPoint(Vector3.one);
 
         Transform origParent = CombineTexture.transform.parent;
         CombineTexture.transform.parent = null;
         CombineTexture.transform.localScale = new Vector3(topRight.x - bottomLeft.x, topRight.y - bottomLeft.y, 1);
         CombineTexture.transform.parent = origParent;
     }
And then render the whole screen into a texture
 private IEnumerator CombinePaintAndCanvas()
     {
         Texture2D overlay = (Texture2D)Overlay.renderer.material.mainTexture;
 
         RenderTexture rt = new RenderTexture((int)UICamera.currentCamera.pixelWidth, (int)UICamera.currentCamera.pixelHeight, 24, RenderTextureFormat.Default);
 
         Texture2D tex = new Texture2D((int)UICamera.currentCamera.pixelWidth, (int)UICamera.currentCamera.pixelHeight, TextureFormat.RGB24, false);
         yield return new WaitForEndOfFrame();
 
         UICamera.currentCamera.targetTexture = rt;
         UICamera.currentCamera.Render();
         RenderTexture.active = rt;
 
         tex.ReadPixels(new Rect(0, 0, (int)UICamera.currentCamera.pixelWidth, (int)UICamera.currentCamera.pixelHeight), 0, 0);
 
         tex.Apply();
 
         CombineTexture.mainTexture = tex;
 
         UICamera.currentCamera.targetTexture = null;
         RenderTexture.active = null;
         Destroy(rt);
     }
Anybody any idea what I'm doing wrong? Or is this that kind of rounding error which is hard to prevent? Thx in advance.
Answer by Ches81 · Mar 09, 2014 at 10:37 AM
Maybe you attach a behaviour to the camera and capture the screen in the "OnPostRender" method. To avoid blurry screens you can turn off the AntiAliasing by setting QualitySettings.antiAliasing = 0 until the capturing process is complete. Afterwards you restore the old settings. Maybe this tutorial is helpful to you. It explains how to capture a screen without a pro license. Link: Render screen to texture in Unity3D (without Pro)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                