Search Unity

Single Pass VR Screen Position

Discussion in 'Shaders' started by ECS_Justin, May 11, 2021.

  1. ECS_Justin

    ECS_Justin

    Joined:
    Dec 5, 2011
    Posts:
    12
    I'm having a problem properly projecting a screen space texture in Single Pass stereo mode. I've been Googling and trying everything I can think of for the past few days and can not get a working solution. Wondering if you could provide some insight.

    Essentially, I'm looking to be able to blur a UI canvas. I'd like to avoid using a GrabPass so currently I'm using a CommandBuffer to spit out the proper RenderTexture. This all seems to be working fine and produces the following:

    View attachment 852305
    *note that this does not have the blur, just testing to make sure it will work for now.

    The problem is then properly using this on the UI shader side. The Unity documentation is a little confusing and no matter what I try I end up with misaligned display in both eyes.

    I was able to finally get a GrabPass to work and thought I could swap that out with the RenderTexture, but that too was incorrect. To get the GrabPass to work correctly I used the following in the vertex function:

    Code (CSharp):
    1. OUT.grabPos = ComputeGrabScreenPos(OUT.vertex);
    and the following in the fragment function:

    Code (CSharp):
    1.  
    2. #if UNITY_SINGLE_PASS_STEREO
    3.      IN.grabPos.xy = TransformStereoScreenSpaceTex(IN.grabPos.xy, IN.grabPos.w);
    4. #endif
    5.  
    6. float2 screenUV = IN.grabPos.xy / IN.grabPos.w;
    7.  
    8. #if UNITY_SINGLE_PASS_STEREO
    9.      float4 scaleOffset = unity_StereoScaleOffset[unity_StereoEyeIndex];
    10.      screenUV = (screenUV - scaleOffset.zw) / scaleOffset.xy;
    11. #endif
    12.  
    13. half4 color = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_GrabTexture, screenUV) * IN.color;
    14.  
    15.  
    Again, replacing _GrabTexture with my RenderTexture does not work. Can anyone provide any insight here?

    Thank You,
    Justin