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 skullthug · Dec 08, 2012 at 04:08 AM · camerascreenshotreadpixelsscreencapture

Is there any way to execute ReadPixels (for capturing a screenshot) but on a camera that is currently not displaying anything on screen?

That might sound like a weird question but here's what I'm trying to do. Basically I want to take a screen shot of the current pose of a character and use that for an icon in a list of saved presets. But I can't simply take a screen shot of what's actually displaying on screen because the lighting isn't very good and there's menu prompts in the way.

I'm looking for a sneaky way to take the character, warp it away outside of the view temporarily into a better lit environment and take the screenshot there. Any ideas how to do this? ReadPixels appears to only work with what is being displayed on screen.

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 skullthug · Dec 11, 2012 at 04:35 AM

The answer is basically no, not without UnityPro and RenderToTexture. Thanks REDDIT http://www.reddit.com/r/Unity3D/comments/14gxyf/is_there_any_way_to_execute_readpixels_for/

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
2

Answer by hardsetting_ · Sep 20, 2013 at 08:00 PM

Actually yes, I've been able to do so. The solution is a bit long but it's actually pretty simple.

First of all you have to place on the scene a new Camera ( let's call it GrabCamera ) with the desired aspect ratio and such; what is shown in this camera is what will be shown in the screenshot.

To do this, you have to create a new Unity Layer: On the top bar click Edit->Project Settings->Tags and then double click on the blank space to the right of an unused Layer to name it ( let's call it GrabLayer ); objects you want to see will be in this layer.

Then you'll have to specify the layer culling mask in the GrabCamera, setting it to GrabLayer.

Now you have to add the GrabLayer layer to the objects you want to see in the screenshot, by selecting them and pressing the layer drop-down menu on the upper right.

The last step is to create a specific script to attach to the GrabCamera so that it does the grabbing stuff at the right moment. Here's what I used for an ortographic camera:

 public class CameraGrabScript : MonoBehaviour
 {    
     public bool grab = true;
     public Texture2D grabTexture;
 
     public Vector2 size = new Vector2( 400.0f, 400.0f );
 
     private void Start()
     {
         this.camera.pixelRect = new Rect( 0.0f, 0.0f, this.size.x, this.size.y );
 
         this.grabTexture = new Texture2D( (int)this.size.x, (int)this.size.y );
     }
 
     private void OnPostRender()
     {
         if( this.grab )
         {
             this.grabTexture.ReadPixels( new Rect( 0, 0, this.size.x, this.size.y ), 0, 0 );
             this.grabTexture.Apply();
 
             this.grab = false;
         }
     }
 }

Basically in the Start function the camera values are set depending on the part of screen I wanted to capture ( not necessary if you've already set the position correctly ). In the OnPostRender function, right after the GrabCamera as finished rendering, if the grab flag is set to true the camera does the grabbing.

The trick here is that the grabbing occurs right after the GrabCamera has finished rendering and the screen hasn't been overwritten by the MainCamera yet.

For this to work correctly is important that the MainCamera's depth is larger that the GrabCamera's so that the former is rendered last and overwrites completely the latter's rendering.

If instead of wanting just some stuff to get screenshot, you want something to be excluded from the grab you have to set the GrabCamera's culling mask accordingly ( Everything but the Excluding layer ).

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

10 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

Related Questions

capture a screen shot and show in the album folder 1 Answer

Can you change ScreenShotCapture Camera? 1 Answer

What is the bottleneck in this iphone code? 3 Answers

Texture2D.ReadPixels and not lose image quality 1 Answer

Using Texture2D.GetPixels() to take a screenshot and then show it on an Image - iOS problems. 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