Search Unity

how do i render what is on the screen for only a frame into a texture

Discussion in 'Scripting' started by CyberTurboPlays, Jul 25, 2015.

  1. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
    hi guys
    i want to grab the screen and save that as a texture of some sort so that i can use it for my game's pause background.
    please give me an example, thanks
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,277
  4. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
  5. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
    still, i would really like to see how to use RenderTexture to make this to work, coz (just as expected, the cost of screen grab to texture2D is too much for mobile), when i pause my game(now, i screen grab as texture2D and use as bg img), a (at least) 0.5 sec freeze before my pause window show up, totally not feasible

    can some one plz show me a example using renderTexture to make this to work(since its playing with the render buffer, i think it will surely faster than grabing all the pixels in the screen grab to texture technique)

    thanks a lot
     
  6. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    So, you're using a disabled camera with targetTexture set to your texture and calling Render() if the game is paused, correct?
     
  7. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
    ye, my case involves disable one of the camera which is shooting the essential elements.
    previously, when i pause i just turn on the 2nd cam which is set to depth only, so it can see through the one underneath, but performance wise, i want to set that 2nd cam to solid color clear flag. so no more see through, and since that, the 1st cam can also be turn off while the 2nd one is on.
    now with no see through, its very ugly with just a plain bg color
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,277
  9. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
    thx for letting me know, man, i can see how they use render texture technique, but sadly, the example shows it still involves pixels reading, encoding, then writing, then its no different than using texture2D.readPixel technique, i reckon it will take exactly the same cost too.

    i thought we could use those renderbuffers frames which has been rendered and kept in G-ram for a couple of frames, which contains byte[], color[] or depth[](from the Unity doc, its said these are the data that to be played with those post render Fx), so i thought maybe i could just grab that straight out of the pool, and have zero cost in doing so:confused:
     
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    What are you actually trying to do? To save the image you have to get it out of the graphics ram and across to long term storage.