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 Endahs · Sep 16, 2014 at 03:39 AM · antialias

Problems taking screenshots using anti-aliasing

Hi folks.

Been Googling for hours and can't find a solution to a problem I've been having with anti-aliasing and taking screenshots.

My script runs through all the cameras in the level and takes a screenshot of them. Everything works nicely and quickly, exporting out 60+ 2048x1280 pics in no time at all. Sounds good.

Here's where it falls down. After enabling anti-aliasing about 75% of the renders will work (and look great and anti-aliased!) but about 25% will fail and save another camera's view as the texture! The cameras that fail fail consistently, but I can't see anything different about those cameras than the ones that work.

Here's my script:

 using UnityEngine;
 using System.Collections;
 
 public class TakeScreenshotMaster : MonoBehaviour {
 
 
 
     public int resWidth         = 2048; 
     public int resHeight         = 1280;
     public string cameraName     = "";
     
     private bool takeHiResShot = false;
     
     public static string ScreenShotName(int width, int height, string cameraName) {
 
         Debug.Log(string.Format("ScreenShotName: Name is now: {0}", cameraName));
 
         return string.Format("d:/screenshots/{4}_{1}x{2}_{3}.png", 
                              Application.dataPath, 
                              width, height, 
                              System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"),
                              cameraName);
 
     }
     
     // Last to run...
     void LateUpdate() {
 
         takeHiResShot |= Input.GetKeyDown("k");
 
         if (takeHiResShot) 
         {
             Debug.Log(string.Format("k press detected!"));
             takeHiResShot = false;
             StartCoroutine(TakeScreenshotsOfEverything());
         }
     }
 
 
     IEnumerator TakeScreenshotsOfEverything()
     {
 
         Debug.Log(string.Format("Printing all screens!"));
 
         // Create new game object to hold all possible cameras...
         GameObject[] cameras = GameObject.FindGameObjectsWithTag("Camera");
         
         // Loop through each tagged camera...
         foreach (GameObject cams in cameras){
 
             // Get next camera...
             Camera theCam = cams.GetComponent<Camera>() as Camera;
             theCam.enabled = true;
 
             yield return new WaitForEndOfFrame();
             
             RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
         
             rt.antiAliasing = 1;
             rt.filterMode = FilterMode.Trilinear;
 
             theCam.targetTexture = rt;
             
             Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
             
             RenderTexture.active = rt;
             theCam.Render();
 
             screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
             
             // Cleanup...
             theCam.targetTexture = null;
             RenderTexture.active = null; // JC: added to avoid errors
             Destroy(rt);
             theCam.enabled = false;
 
             // Write to file...
             byte[] bytes = screenShot.EncodeToPNG();
             string filename = ScreenShotName(resWidth, resHeight, theCam.name);
             System.IO.File.WriteAllBytes(filename, bytes);
             
             Debug.Log("Capture!");
         }  
 
 
     }
 
 
     // Use this for initialization
     void Start () {
         Debug.Log("Master camera reporting for duty!");
 
         // Create new game object to hold all possible cameras...
         GameObject[] cameras = GameObject.FindGameObjectsWithTag("Camera");
 
         // Loop through each tagged camera...
         // Disable each for now...
         foreach (GameObject cams in cameras){
             Camera theCam = cams.GetComponent<Camera>() as Camera;
             theCam.enabled = false;
         }  
 
         // Enable the first camera...
         //Camera firstCamera = cameras [0].GetComponent<Camera> () as Camera;
         //firstCamera.enabled = true;
     }
 
 
 
     // Update is called once per frame
     void Update () {
         //Debug.Log(string.Format("Update: Camera {0} is running!", cameraName));
         //camera.
     }
 
 }
 

Pulling my hair out with this one! Does anyone have any ideas? Like I said, it works 100% if I don't use anti-aliasing, and 75% will work if I enable anti-aliasing, with 25% fail by rendering one of the other working cameras instead.

Cheers, Chris

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Why won't anti-aliasing work in the Editor for me? 2 Answers

Making fonts antialiased at all sizes 0 Answers

Anti-aliasing on Android 1 Answer

Anti-Aliasing Methods 1 Answer

Antialias LineRenderer Lines 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