• 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
Question by Ross_S · Apr 29, 2013 at 03:36 PM · texture2dscreensizerendertexturemaximum

RenderTexture to capture an area bigger than Screen on IOS

I'm trying to use RenderTexture to capture a 1280x720 texture on the iPhone4, and the output seems to be limited to the screen proportions. in pseudo code what i'm doing is:

create a RenderTexture 1280x720 (called rt from now on)

change the ortho size of the camera to 360

set targetTexture for Camera to rt.

call Camera.Render() (t$$anonymous$$s renders a 1280x720 plane set at position 0,0 with the video texture on it)

set RenderTexture.active to rt

Create a Texture2D (call it tex) of size 1280x720

call tex.ReadPixels(Rect(1280,720),0,0)

tex.Apply

and then EncodeToPNG

and basically the output i'm getting is that only 960x640 (iphone 4 screen size) pixels of the output texture are filled in. The image i've uploaded is the output from the device - the output from the player is roughly the same though slightly more garbled.) Is there some limitation that won't allow the camera to render bigger than the screen size? Anybody know-

alt text

btw i tried with RenderTextures of sizes 2048x1024 and t$$anonymous$$s worked fine on the Player - but still produced the result as seem in the image when i tried it from the device.

EDIT: Okay I've tried changing to use an Untagged camera as Fattie suggested but I'm still seeing the same result so I'm posting the code here:

     IEnumerator TakeShotCo () 
     {
         yield return new WaitForEndOfFrame();
 
         RenderTexture rt = new RenderTexture((int)(1280.0f),(int)(720.0f),24);
 
         Vector3 newScale = new Vector3(-128,1,-72);        
         Globals.g_mainLoop.cameraPlane.transform.localScale = newScale;        
                 
         UnityEngine.Camera virtuCam = GameObject.Find ("virtuCam").camera;        
                     
         virtuCam.targetTexture = rt;
         virtuCam.Render();
                                 
         RenderTexture.active = rt;        
                 
         byte[] pngShot = null;
                     
         Texture2D tex = new Texture2D(1280,720,TextureFormat.RGB24,false);
         tex.ReadPixels(new Rect(0,0,1280,720), 0, 0);
         tex.Apply();
             
         RenderTexture.active = null;
         Destroy(rt);
         
         pngShot = tex.EncodeToPNG();
         
         virtuCam.targetTexture = null;                
         
         System.IO.File.WriteAllBytes(Utilties.pathForDocumentsFile("texture1280x720"), pngShot );
      }

any Ideas appreciated. Thanks

here's what the virtuCam looks like... alt text

screen shot 2013-04-30 at 09.21.44.png (91.2 kB)
screen shot 2013-04-29 at 16.23.35.png (223.4 kB)
Comment
Fattie
Loius

People who like this

2 Show 9
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 Fattie · Apr 29, 2013 at 04:03 PM 0
Share

Hmm something is wrong, perhaps you should post your code ??

Is your problem this: (sorry I'm a bit friend from coding all day and I can't follow you exactly)

You shouldn't be using the actual camera you use to see stuff in the game.

Make a new camera in the scene called virtuCam (you must use that name - because it's funny)

Flag it as untagged, and everywhere else in your scene never ever just implictly find your scene camera (with hat "main camera" rubbish) find it explicitly. And find your virtuCam explicitly

 virtualCam = FindUnderHereNamed("virtuCam").camera;

then just follow the usual approach ..

 function _freakyExampleCode( )
     {
     // let's go....
     
     var tempRT:RenderTexture = new RenderTexture(picW,picH, 24 );
     // the thingy on the end can be 0,16,24
     // formats like RenderTextureFormat.Default, ARGB32 blah blah
     
     virtualCam.targetTexture = tempRT;
     
     var virtualPhoto:Texture2D =
           new Texture2D( picW,picH, TextureFormat.RGB24, false);
     // false, meaning no need for mipmaps.  mipmaps can go to hell
     
     virtualCam.Render(); 
     RenderTexture.active = tempRT;
     
     virtualPhoto.ReadPixels(Rect(0, 0, picW,picH), 0, 0);
     
     RenderTexture.active = null; // redundant code is bad code 
     Destroy(tempRT);
     
     var bytes:byte[];
     bytes = virtualPhoto.EncodeToPNG();
     
     System.IO.File.WriteAllBytes( some filename here, bytes );
     // virtualCam.SetActive(false); ...no great need for this
     }


again you may have to post your code.

and you can not use the same camera. (Like you report it works in the editor ... because you can just set the size of the game window to whatever. A very confusing aspect of Unity. I find one should always set the game windo to an actual iPad (/ phone) size to avoid horror.

avatar image Ross_S Fattie · Apr 29, 2013 at 04:10 PM 0
Share

Thanks Fattie, I am using one of my in-game cameras so I'm going to try adding an untagged virtuCam as you suggest and see how we go... if still no dice then i'll post the code... :)

avatar image Ross_S Fattie · Apr 29, 2013 at 05:10 PM 0
Share

Hi Fattie, hmm I'm still seeing the same thing - i've posted the code i'm using above .. the camera is definitely untagged. any clues in there?

avatar image Ross_S Fattie · Apr 30, 2013 at 08:31 AM 0
Share

Yes, I'm pretty sure it's using the virtuCam - the code I posted above is the code that's being run and i put in a breakpoint and the virtuCam pointer there shows an orthographic size of 360 which is only true for that untagged cam. I also noticed when inspecting it though that the virtuCam's pixelRect was 960x640 ... i tried to manually change that with the code -

 Rect camRect = new Rect(0,0,1280,720);        
 virtuCam.pixelRect = camRect;

but on inspection that appeared to be completely ignored - maybe its max rect is tied in to the Screen. width/height parameters?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

How do I find max texture size or max RenderTexture size 0 Answers

Object resolution 0 Answers

How to make game recognise Screen resolution on startup 1 Answer

is there a way to make textures bigger then 4096 2 Answers

How to save a RenderTexture to a png from a different camera? 1 Answer


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