Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kling0ne · Sep 13, 2013 at 09:07 AM · graphicsscreenrendertexturescreenshot

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fherbst · Sep 13, 2013 at 09:56 AM

You should read about the half-pixel offset (e.g. here or here).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple cameras, depths, and image effects! 2 Answers

Finding the right ortho size to fill the screen with an object 1 Answer

modify textures at runtime? 3 Answers

Does Graphics.DrawMeshNow() block the thread until rendering is complete 0 Answers

Blitting a Texture once 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges