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
1
Question by BenMeijering · May 12, 2012 at 01:15 PM · camerarendertexturescreenshotmultiple cameras

Rendering screenshot using multiple cameras and one rendertexture

Hi everyone,

I want to be able to take a screenshot with arbitrary dimensions. All enabled cameras must be used. What I have so far is this:

 public static Texture2D getScreenshot(int a_Width, int a_Height)
 {
     List<Camera> cameras = new List<Camera>(Camera.allCameras);
 // sort cameras using Depth
     cameras.Sort(new CameraComparer());
     RenderTexture renderTexture = RenderTexture.GetTemporary(a_Width, a_Height, 24);
     RenderTexture.active = renderTexture;    

     foreach (Camera camera in cameras)
     {
         if (camera.enabled)
         {
             float fov = camera.fov;
             camera.targetTexture = renderTexture;
             camera.Render();
             camera.targetTexture = null;
             camera.fov = fov;
         }
     }

     Texture2D result = new Texture2D(a_Width, a_Height, TextureFormat.ARGB32, false);
     result.ReadPixels(new Rect(0.0f, 0.0f, a_Width, a_Height), 0, 0, false);
     result.Apply();

     RenderTexture.active = null;

     RenderTexture.ReleaseTemporary(renderTexture);

     return result;
 }

The testcase I am using right now has two cameras. One that renders the world, and a second one that renders the sky and clouds (rendered first with a more distant far clipping plane). The result I am getting is the following: alt text

The sky seems to be rendered upside down. But that's not the only thing that's going on ,the sky is a sphere, so it seems odd that the world is also mirrored. Probably from a previous render to the rendertexture ? Also, the sky seems to be too white.

Does anyone have any experience in this area ?

Any help would be appreciated.

Cheers,

Ben

Screenshots.jpg (133.2 kB)
Comment
Add comment · Show 1
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 atrajano · Jun 17, 2019 at 04:39 AM 0
Share

I am new to Unity, but I am confused why you need RenderTexture.active AND camera.targetTexture. I would think camera.targetTexture was enough, but it does not appear so.

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Wierd Screen Shot Problem, texture of screen shot looks different in editor and in system. 1 Answer

Problem with screenshot on render texture 0 Answers

Taking huge screenshots using camera array? 3 Answers

Taking screenshot from a second camera 0 Answers

Render Splitscreen to RenderTexture 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