Search Unity

Screenshot simultaneously left and right eye view

Discussion in 'Scripting' started by Realter, Jan 13, 2021.

  1. Realter

    Realter

    Joined:
    Oct 5, 2020
    Posts:
    9
    Hello,
    in a previous post I found out how to make a screenshot of the game view using this code:

    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour
    2. {
    3.     void OnGUI()
    4.     {
    5.         if (GUILayout.Button("Capture"))
    6.         {
    7.             ScreenCapture.CaptureScreenshot("image.png");
    8.         }
    9.     }
    10. }
    Do you know how I could make in a way similar to the script shown above a simultaneously screenshot of the scene seen by both eyes? I mean something like in the picture attached.

    I saw on the documentation that exists a StereoScreenCaptureMode but I don't know how I could use it in a script, I'm new to C# coding.

    Thank you
     

    Attached Files:

    Last edited: Jan 14, 2021
  2. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    It should be possible, but I've been fiddling with it and haven't gotten it to work. You'd need to set up the scene's rendering to be stereo (XR) to set the mode correctly. Sorry I can't be more help than that (so far)...
     
    Realter likes this.
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I haven't even seen an actual VR set yet so I don't have any experience developing on one, but from looking at the API it looks like when you call
    Code (CSharp):
    1. ScreenCapture.CaptureScreenshot("image.png");
    it defaults to the LeftEye mode of the "StereoScreenCaptureMode" enumeration, what an enumeration is is just a marker for the type, it's a secondary optional argument of the ScreenCapture.CaptureScreenshot() function and if you don't provide the optinal arguement it behaves like you say
    Code (CSharp):
    1. ScreenCapture.CaptureScreenshot("image.png", ScreenCapture.StereoScreenCaptureMode.LeftEye );
    I think all you gotta do is say
    Code (CSharp):
    1. ScreenCapture.CaptureScreenshot("image.png", ScreenCapture.StereoScreenCaptureMode.BothEyes);
    https://docs.unity3d.com/ScriptReference/ScreenCapture.CaptureScreenshot.html
    https://docs.unity3d.com/ScriptReference/ScreenCapture.StereoScreenCaptureMode.html

    if what I'm saying makes no sense you should learn some basic C# and coding before diving in too deep into unity, it won't take too long and you'll benefit a lot from it if you're going to develop stuff.
     
    Realter likes this.
  4. Realter

    Realter

    Joined:
    Oct 5, 2020
    Posts:
    9
    Thank you very much, it worked perfectly!
     
  5. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    Curious, my screenshots all look the same, even with the different StereoScreenCaptureMode arguments. Was there an additional setting needed?
     
  6. Realter

    Realter

    Joined:
    Oct 5, 2020
    Posts:
    9
    Here is the code I used for getting a screenshot of both left and right eye:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BothEyesScreen : MonoBehaviour
    6. {
    7.     void OnGUI()
    8.     {
    9.         if (GUILayout.Button("Capture"))
    10.         {
    11.             ScreenCapture.CaptureScreenshot("image.png", ScreenCapture.StereoScreenCaptureMode.BothEyes);
    12.         }
    13.     }
    14.  
    15. }
    Before taking the screenshot you want, in the game view you have to set Left Eye, Right Eye or Both Eyes according to what you wanna get.
     
    Last edited: Jan 15, 2021
  7. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    Hmm, I did the same, and all my screenshots look identical, even with "Both Eyes" checked in the Main Camera Inspector. When you say "game view" is that what you're referring to?
     
  8. Realter

    Realter

    Joined:
    Oct 5, 2020
    Posts:
    9
    I changed nothing in the main camera inspector. I'm referring to the game view in your unity project, as shown in the picture attached, you can choose your favourite view (left, right or both) when your project is in Play mode.
     

    Attached Files:

  9. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    Ah, you must have something additional set up, I don't have that option.
     
  10. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Is your project set to a VR platform?
     
  11. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    I thought it was, but am probably missing something. I'll get it figured out, don't want to keep dragging out the thread. Thanks for the info!