Search Unity

Replace Texture

Discussion in 'AR/VR (XR) Discussion' started by Scrapemist, May 16, 2015.

  1. Scrapemist

    Scrapemist

    Joined:
    May 16, 2015
    Posts:
    16
    I am building a cinema for Cardboard, where I want to show 3D sbs videos using a separate screen for each eye.
    So I'm displaying the left half of the video to the left eye screen. But in order to have the other half in sync, I copied the video as a texture to the right eye screen with the following code:

    Code (CSharp):
    1.     void Update () {
    2.  
    3.         if(GetComponent<MeshRenderer>().material.mainTexture == null)
    4.         {
    5.             if(m_srcMedia != null)
    6.             {
    7.                 if(m_srcMedia.GetCurrentState() == MediaPlayerCtrl.MEDIAPLAYER_STATE.PLAYING)
    8.                 {
    9.                     GetComponent<MeshRenderer>().material.mainTexture = m_srcMedia.GetVideoTexture();
    10.                 }
    11.             }
    12.  
    13.         }
    14.  
    15.    
    16.     }

    This works perfectly, but only when the default texture for the right screen is set to None, hence the Null.
    This results in a white screen for the right eye, before the video is loaded.

    How can I add a texture and have it replaced by the videotexture?
     
  2. ThomasCreate

    ThomasCreate

    Joined:
    Feb 23, 2015
    Posts:
    81
    Why can't you just have both halves share the same material? That way all objects using that material will get updated in sync.
     
  3. Scrapemist

    Scrapemist

    Joined:
    May 16, 2015
    Posts:
    16
    Because I want to display 3d sbs footage each material has a different offset to let each screen show one half of the video. But I have fixed the problem just by deleting the following line

    Code (CSharp):
    1. if(GetComponent<MeshRenderer>().material.mainTexture == null)
    :)
     
  4. ThomasCreate

    ThomasCreate

    Joined:
    Feb 23, 2015
    Posts:
    81
    You don't have to use the material uv offset property to have an offset uv; you can just map the uv correctly for each eye in your modelling program.