Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ReadPixels - Render Skybox?

Discussion in 'Scripting' started by Paden, Mar 11, 2015.

  1. Paden

    Paden

    Joined:
    Sep 13, 2013
    Posts:
    13
    Hello,

    I am using Texture2D.ReadPixels in order to take a "screenshot" of one of the cameras in my scene. This works, however, the skybox is capturing properly (or it IS capturing properly and it just not what I want).

    You can see what I mean below. The preview of the image is seen on the right. I think it's capturing the skybox's alpha channel and the black texture behind it is making it look a lot darker.

    Is there any way I can get it to NOT capture the skybox's alpha channel?



    Thanks!
     
  2. Paden

    Paden

    Joined:
    Sep 13, 2013
    Posts:
    13
    No one?
     
  3. Paden

    Paden

    Joined:
    Sep 13, 2013
    Posts:
    13
    Fixed it:

    Code (CSharp):
    1. Texture2D tex = new Texture2D((int)Mathf.Floor(camera.rect.width*Screen.width), (int)Mathf.Floor(camera.rect.height*Screen.height));
    2. tex.ReadPixels(new Rect((int)Mathf.Floor(camera.rect.x*Screen.width), (int)Mathf.Floor(camera.rect.y*Screen.height), (int)Mathf.Floor(camera.rect.width*Screen.width), (int)Mathf.Floor(camera.rect.height*Screen.height)), 0, 0);
    3. Color[] _c = tex.GetPixels();
    4.  
    5. for(int i=0; i<_c.Length; i++){
    6.     _c[i].a = 255;
    7. }
    8.  
    9. tex.SetPixels (_c);
    10. tex.Apply();
    Just iterated through the pixels and manually changed all their alpha values to 255.
     
    JoeStrout likes this.