Search Unity

Show Light Field Image on the HTC Vive

Discussion in 'AR/VR (XR) Discussion' started by husan0812, Jun 11, 2019.

  1. husan0812

    husan0812

    Joined:
    Jul 26, 2018
    Posts:
    1
    I'm new to use Unity, and this is my first time asking the question.
    Now I need to use both the color image and the depth image of the scene(so I use two cameras) to calculate the light field image which I use the DLL of the light field algorithm to do that.
    The problem is I don't know how to let the light field image just show on the HTC Vive.
    Here is my code.
    Code (CSharp):
    1.  unsafe void OnRenderImage(RenderTexture source, RenderTexture destination)
    2.     {
    3.         //RenderTexture Final;
    4.         Graphics.Blit(source, destination, mat);
    5.    
    6.         RenderTexture.active = source;
    7.  
    8.         //---------------------------------------vary---------------------------------------
    9.         colorImageTexture.ReadPixels(new Rect(0, 0, source.width, source.height), 0, 0, true);
    10.         colorImageTexture.Apply();
    11.         pix = colorImageTexture.GetPixels32();
    12.         //------------------------------------vary Done-------------------------------------
    13.  
    14.         RenderTexture currentRT = RenderTexture.active; // save current active rendertexture
    15.  
    16.         RenderTexture.active = destination;             //depth
    17.  
    18.         //---------------------------------------vary---------------------------------------
    19.         depthImageTexture.ReadPixels(new Rect(0, 0, destination.width, destination.height), 0, 0);
    20.         depthImageTexture.Apply();
    21.         depth = depthImageTexture.GetPixels32();
    22.  
    23.    
    24.         Output = colorImageTexture.GetPixels32();
    25.         GCHandle pinnedArray = GCHandle.Alloc(Output, GCHandleType.Pinned);
    26.    
    27.      //DLL of the light field algorithm
    28.        LF_DLL(pinnedArray.AddrOfPinnedObject(), pix , depth ,4.1f * 0.95f, height, width);                       //LF_DLLpixels, Output
    29.         LFImageTexture.SetPixels32(Output);
    30.         LFImageTexture.Apply();
    31.         SavePNG(LFImageTexture, "./depthImages/color_GC_LF" + image_id + ".png");
    32.         pinnedArray.Free();
    33.  
    34.         Graphics.Blit(source, targetTexture);//I don't know how to show the light field image on the scene
    35.  
    36.         /
    37.     }

    Do I use the correct function?
    Or anyone know other methods to achieve that?