Search Unity

Question Sampling a pixel from Texture2D not working on Quest 2

Discussion in 'VR' started by sgeiger, Jan 26, 2023.

  1. sgeiger

    sgeiger

    Joined:
    Feb 22, 2018
    Posts:
    2
    I'm trying to sample color from a pixel of a RenderTexture, using the method of copying the RT to a Texture2D and then sampling with GetPixel:

    Code (CSharp):
    1.                 RenderTexture.active = renderTex;
    2.                 tex2D.ReadPixels(new Rect(0, 0, tex2D.width, tex2D.height), 0, 0);
    3.                 tex2D.Apply();
    4.                 Color col = tex2D.GetPixelBilinear(pixelPos.x, pixelPos.y);
    This works great on the editor, but when building for the quest it gives some weird behaviour: most of the time the color it returns is black (regardless of the real texture color), but every now and then it "flashes" the correct color for a single frame.
    Couldn't find a solution for this specific behaviour anywhere...
     
  2. Music_Corner

    Music_Corner

    Joined:
    Mar 8, 2020
    Posts:
    23
    I have same issue. Did you solve it?
     
  3. sgeiger

    sgeiger

    Joined:
    Feb 22, 2018
    Posts:
    2
    No. Had to work around it. Sorry.
     
  4. Music_Corner

    Music_Corner

    Joined:
    Mar 8, 2020
    Posts:
    23